

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>agpy.pyflagger &mdash; agpy 0.1.2 documentation</title>
    
    <link rel="stylesheet" href="../../_static/extra.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="agpy 0.1.2 documentation" href="../../index.html" />
    <link rel="up" title="agpy" href="../agpy.html" />
     
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setDomainName', 'pyspeckit.bitbucket.org']);
      _gaq.push(['_setAllowHash', false]);
      _gaq.push(['_trackPageview']);


    </script>
    <link rel="stylesheet" type="text/css" href="../../_static/extra.css" />
  </head>
  <body>
    <div class="header-wrapper">
      <div class="header">
        <h1><a href="../../index.html">agpy 0.1.2 documentation</a></h1>
        <div class="rel">
          <a href="http://agpy.googlecode.com">agpy Home </a>  |
          <a href=../../index.html>Docs Home </a>  |
          <a href="http://code.google.com/p/agpy/w/list">Wiki</a>  |
          <a href=../../search.html>Search </a>
        </div>
       </div>
    </div>

    <div class="content-wrapper">
      <div class="content">
        <div class="document">
            
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for agpy.pyflagger</h1><div class="highlight"><pre>
<span class="c">#!python</span>

<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span><span class="s">&#39;ignore&#39;</span><span class="p">,</span><span class="s">&#39;masked&#39;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">pylab</span>
<span class="kn">from</span> <span class="nn">pylab</span> <span class="kn">import</span> <span class="o">*</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span> <span class="ow">in</span> <span class="n">pylab</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>  
    <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">v</span><span class="p">,</span><span class="s">&#39;__module__&#39;</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">v</span><span class="o">.</span><span class="n">__module__</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="nb">locals</span><span class="p">()[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">__module__</span> <span class="o">=</span> <span class="s">&#39;pylab&#39;</span>
<span class="kn">import</span> <span class="nn">matplotlib</span>
<span class="kn">import</span> <span class="nn">pyfits</span>
<span class="kn">import</span> <span class="nn">numpy</span> 
<span class="kn">from</span> <span class="nn">mad</span> <span class="kn">import</span> <span class="n">MAD</span><span class="p">,</span><span class="n">nanmedian</span>
<span class="c">#from matplotlib import patches</span>
<span class="kn">from</span> <span class="nn">matplotlib.patches</span> <span class="kn">import</span> <span class="n">Rectangle</span><span class="p">,</span><span class="n">FancyArrow</span><span class="p">,</span><span class="n">Circle</span><span class="p">,</span><span class="n">Ellipse</span>
<span class="kn">from</span> <span class="nn">matplotlib.lines</span> <span class="kn">import</span> <span class="n">Line2D</span>
<span class="kn">from</span> <span class="nn">matplotlib.widgets</span> <span class="kn">import</span> <span class="n">Cursor</span><span class="p">,</span> <span class="n">MultiCursor</span>
<span class="kn">import</span> <span class="nn">matplotlib.cm</span> <span class="kn">as</span> <span class="nn">cm</span>
<span class="c">#from Scientific.IO import NetCDF</span>
<span class="c">#from scipy.io import netcdf</span>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">scipy.optimize</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="k">pass</span> <span class="c"># let the error get picked up down the line</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">import</span> <span class="nn">copy</span>
<span class="kn">import</span> <span class="nn">idlsave</span>
<span class="kn">import</span> <span class="nn">gaussfitter</span>
<span class="kn">import</span> <span class="nn">agpy.mpfit</span> <span class="kn">as</span> <span class="nn">mpfit</span>
<span class="kn">from</span> <span class="nn">PCA_tools</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">AG_image_tools.drizzle</span> <span class="kn">import</span> <span class="n">drizzle</span>
<span class="kn">from</span> <span class="nn">agpy</span> <span class="kn">import</span> <span class="n">smooth</span>
<span class="kn">from</span> <span class="nn">guppy</span> <span class="kn">import</span> <span class="n">hpy</span>
<span class="n">heapy</span> <span class="o">=</span> <span class="n">hpy</span><span class="p">()</span>

<span class="n">matplotlib</span><span class="o">.</span><span class="n">rcParams</span><span class="p">[</span><span class="s">&#39;image.origin&#39;</span><span class="p">]</span><span class="o">=</span><span class="s">&#39;lower&#39;</span>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">rcParams</span><span class="p">[</span><span class="s">&#39;image.interpolation&#39;</span><span class="p">]</span><span class="o">=</span><span class="s">&#39;nearest&#39;</span>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">rcParams</span><span class="p">[</span><span class="s">&#39;image.aspect&#39;</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">rcParams</span><span class="p">[</span><span class="s">&#39;axes.color_cycle&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">list</span><span class="p">(</span><span class="n">clr</span><span class="p">)</span> <span class="k">for</span> <span class="n">clr</span> <span class="ow">in</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">cm</span><span class="o">.</span><span class="n">brg</span><span class="p">(</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">144</span><span class="p">))]</span>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">defaultParams</span><span class="p">[</span><span class="s">&#39;image.origin&#39;</span><span class="p">]</span><span class="o">=</span><span class="s">&#39;lower&#39;</span>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">defaultParams</span><span class="p">[</span><span class="s">&#39;image.interpolation&#39;</span><span class="p">]</span><span class="o">=</span><span class="s">&#39;nearest&#39;</span>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">defaultParams</span><span class="p">[</span><span class="s">&#39;image.aspect&#39;</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span>
<span class="k">if</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">rcParams</span><span class="p">[</span><span class="s">&#39;text.usetex&#39;</span><span class="p">]:</span> <span class="n">texOn</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">else</span><span class="p">:</span> <span class="n">texOn</span> <span class="o">=</span> <span class="bp">False</span>
<span class="c"># matplotlib.rcParams[&#39;text.usetex&#39;]=False</span>
<span class="c"># matplotlib.defaultParams[&#39;text.usetex&#39;]=False</span>

<span class="k">class</span> <span class="nc">lazydata</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">varname</span><span class="p">,</span> <span class="n">structname</span><span class="o">=</span><span class="s">&#39;bgps&#39;</span><span class="p">,</span> <span class="n">reshape</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">flag</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">varname</span> <span class="o">=</span> <span class="n">varname</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structname</span> <span class="o">=</span> <span class="n">structname</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">reshape</span> <span class="o">=</span> <span class="n">reshape</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flag</span> <span class="o">=</span> <span class="n">flag</span>

    <span class="k">def</span> <span class="nf">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">attribute</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">attribute</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__get__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="n">t0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">):</span>
            <span class="c"># technically I don&#39;t think this should ever be called</span>
            <span class="c"># but it is. ARGH.</span>
            <span class="c">#print &quot;Getting (instead of computing) %s&quot; % self.varname</span>
            <span class="k">return</span> <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Computing </span><span class="si">%s</span><span class="s"> &quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">varname</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">flag</span><span class="p">:</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">]</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">structname</span><span class="p">][</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="n">obj</span><span class="o">.</span><span class="n">whscan</span><span class="p">,:]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s">&#39;float&#39;</span><span class="p">)</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">][</span><span class="n">obj</span><span class="o">.</span><span class="n">whempty</span><span class="p">,:]</span> <span class="o">=</span> <span class="n">NaN</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">datashape</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">]</span> <span class="o">=</span> <span class="n">nantomask</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">])</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">]</span><span class="o">.</span><span class="n">mask</span><span class="p">[</span><span class="n">obj</span><span class="o">.</span><span class="n">flags</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
                <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
                    <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">]</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">flags</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># flagging is extra work, skip it but still do the reshaping aspects</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">]</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">structname</span><span class="p">][</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="n">obj</span><span class="o">.</span><span class="n">whscan</span><span class="p">,:]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s">&#39;float&#39;</span><span class="p">)</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">datashape</span>

            <span class="c"># not used if self.reshape is not None:</span>
            <span class="c"># not used     obj.__dict__[self.varname] = reshape( obj.mapstr[self.varname][0][obj.whscan,:] , obj.datashape )</span>
            <span class="k">print</span> <span class="s">&quot;Finished computing </span><span class="si">%s</span><span class="s"> in </span><span class="si">%0.3g</span><span class="s"> seconds&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">,</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">t0</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">obj</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">]</span>

<div class="viewcode-block" id="Flagger"><a class="viewcode-back" href="../../pyflagger.html#agpy.pyflagger.Flagger">[docs]</a><span class="k">class</span> <span class="nc">Flagger</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Write out a file with appropriate flagging commands for use in IDL / later editing</span>
<span class="sd">    Example:</span>

<span class="sd">        import pyflagger</span>
<span class="sd">        f = pyflagger.Flagger(&#39;050906_o11_raw_ds5.nc_indiv13pca_timestream00.fits&#39;,&#39;050906_o11_raw_ds5.nc&#39;)</span>
<span class="sd">        f.plotscan(0)</span>
<span class="sd">        f.close()</span>

<span class="sd">    Key commands:</span>
<span class="sd">      left click - flag</span>
<span class="sd">      right click - unflag</span>
<span class="sd">      n - next scan</span>
<span class="sd">      p - previous scan</span>
<span class="sd">      q - save and quit</span>
<span class="sd">      Q - quit (no save)</span>
<span class="sd">      . - point to this point in the map</span>
<span class="sd">      f - plot footprint of array at this time point</span>
<span class="sd">      R - reverse order of flag boxes (to delete things hiding on the bottom)</span>
<span class="sd">      r - redraw</span>
<span class="sd">      d - delete flag box</span>
<span class="sd">      t - flag timepoint</span>
<span class="sd">      s - flag scan</span>
<span class="sd">      w - flag Whole scan (this is the same as s, except some python backends catch / steal &#39;s&#39;)</span>
<span class="sd">      S - unflag scan</span>
<span class="sd">      b - flag bolometer</span>
<span class="sd">      T - unflag timepoint</span>
<span class="sd">      B - unflag bolometer</span>
<span class="sd">      c - toggle current scan</span>
<span class="sd">      v - display data value</span>
<span class="sd">      P - display the PCA decomposition of the displayed timestream</span>
<span class="sd">      o - make a map of the array at the sampled time</span>
<span class="sd">      z - display the power spectra of the displayed timestream (use &#39;C&#39; to plot one)</span>
<span class="sd">      Z - display the power spectra of the displayed timestream over all time</span>
<span class="sd">      C,L - plot Column/Line</span>
<span class="sd">      j - plot whole timestream for selected bolo</span>
<span class="sd">      a - create a footprint movie between two selected points</span>
<span class="sd">      M,m - flag highest, lowest point in map</span>
<span class="sd"> </span>
<span class="sd">    Map Key Commands:</span>
<span class="sd">      c - toggle current scan</span>
<span class="sd">      . - show point in timestream</span>
<span class="sd">      click - show point in timestream</span>
<span class="sd">      middle click - list all points that contribute to that pixel</span>
<span class="sd">      r - redraw</span>

<span class="sd">    &quot;&quot;&quot;</span>



    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">debug</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">npca</span><span class="o">=</span><span class="mi">13</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="c"># Initialize plots first</span>
        <span class="n">pylab</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">pylab</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="n">figsize</span><span class="o">=</span><span class="p">[</span><span class="mi">16</span><span class="p">,</span><span class="mi">12</span><span class="p">])</span>
        <span class="n">pylab</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="n">figsize</span><span class="o">=</span><span class="p">[</span><span class="mi">16</span><span class="p">,</span><span class="mi">12</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">debug</span> <span class="o">=</span> <span class="n">debug</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">npca</span> <span class="o">=</span> <span class="n">npca</span>
        <span class="k">if</span> <span class="n">filename</span><span class="p">[</span><span class="o">-</span><span class="mi">4</span><span class="p">:]</span> <span class="o">==</span> <span class="s">&#39;fits&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_loadfits</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">filename</span><span class="p">[</span><span class="o">-</span><span class="mi">3</span><span class="p">:]</span> <span class="o">==</span> <span class="s">&#39;sav&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_loadsav</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">help</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span>

<span class="s">    Key commands:</span>
<span class="s">      left click - flag</span>
<span class="s">      right click - unflag</span>
<span class="s">      n - next scan</span>
<span class="s">      p,N - previous scan</span>
<span class="s">      q - save and quit</span>
<span class="s">      Q - quit (no save)</span>
<span class="s">      . - point to this point in the map</span>
<span class="s">      f - plot footprint of array at this time point</span>
<span class="s">      R - reverse order of flag boxes (to delete things hiding on the bottom)</span>
<span class="s">      r - redraw</span>
<span class="s">      d - delete flag box</span>
<span class="s">      t - flag timepoint</span>
<span class="s">      s - flag scan</span>
<span class="s">      w - flag Whole scan (this is the same as s, except some python backends catch / steal &#39;s&#39;)</span>
<span class="s">      S,W - unflag scan</span>
<span class="s">      b - flag bolometer</span>
<span class="s">      T - unflag timepoint</span>
<span class="s">      B - unflag bolometer</span>
<span class="s">      c - toggle current scan</span>
<span class="s">      v - display data value</span>
<span class="s">      P - display the PCA decomposition of the displayed timestream</span>
<span class="s">      o - make a map of the array at the sampled time</span>
<span class="s">      z - display the power spectra of the displayed timestream (use &#39;C&#39; to plot one)</span>
<span class="s">      Z - display the power spectra of the displayed timestream over all time</span>
<span class="s">      C,L - plot Column/Line</span>
<span class="s">      j - plot whole timestream for selected bolo</span>
<span class="s">      a - create a footprint movie between two selected points</span>
<span class="s">      M,m - flag highest, lowest point in map</span>
<span class="s">      e - expsub current plane</span>
<span class="s"> </span>
<span class="s">    Map Key Commands:</span>
<span class="s">      c - toggle current scan</span>
<span class="s">      . - show point in timestream</span>
<span class="s">      click - show point in timestream</span>
<span class="s">      middle click - list all points that contribute to that pixel</span>
<span class="s">      r - redraw</span>

<span class="s">        &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">_loadfits</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">ncfilename</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">flagfile</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">mapnum</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">fnsearch</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span>
                <span class="s">&#39;([0-9]{6}_o[0-9b][0-9]_raw_ds5.nc)(_indiv[0-9]{1,2}pca)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="n">ncsearch</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span>
                <span class="s">&#39;[0-9]{6}_o[0-9b][0-9]_raw_ds5.nc&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">ncfilename</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">fnsearch</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Couldn&#39;t find the correct prefix in the filename&quot;</span> \
                    <span class="o">+</span><span class="s">&quot; - expected form like 050906_o11_raw_ds5.nc_indiv13pca_timestream00.fits&quot;</span>
            <span class="k">return</span>
        <span class="n">mapnumsearch</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">&#39;([0-9]{2})(\.fits)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">mapnumsearch</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">mapnum</span><span class="o">==</span><span class="s">&#39;&#39;</span><span class="p">:</span>
            <span class="n">mapnum</span> <span class="o">=</span> <span class="n">mapnumsearch</span><span class="o">.</span><span class="n">groups</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">mapnum</span> <span class="o">=</span> <span class="s">&#39;01&#39;</span>

        <span class="k">if</span> <span class="n">fnsearch</span><span class="o">.</span><span class="n">groups</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">ncsearch</span><span class="o">.</span><span class="n">group</span><span class="p">():</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span> <span class="o">=</span> <span class="n">ncfilename</span> <span class="c"># self.pathprefix+fnsearch.groups()[0]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">readncfile</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Warning: the NCDF filename doesn&#39;t match the input fits file name.&quot;</span>\
                    <span class="o">+</span> <span class="s">&quot;You&#39;ll probably get errors and your work won&#39;t be saved.&quot;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pathprefix</span><span class="o">+</span><span class="n">fnsearch</span><span class="o">.</span><span class="n">groups</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">fileprefix</span> <span class="o">=</span> <span class="n">fnsearch</span><span class="o">.</span><span class="n">group</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">pathprefix</span> <span class="o">=</span> <span class="n">filename</span><span class="p">[:</span><span class="n">fnsearch</span><span class="o">.</span><span class="n">start</span><span class="p">()]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tsfn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pathprefix</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">fileprefix</span><span class="o">+</span><span class="s">&quot;_timestream00.fits&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tsfile</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tsfn</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mapfn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pathprefix</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">fileprefix</span><span class="o">+</span><span class="s">&quot;_map&quot;</span><span class="o">+</span><span class="n">mapnum</span><span class="o">+</span><span class="s">&quot;.fits&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mapfile</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mapfn</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">map</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapfile</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">[</span><span class="n">numpy</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">)]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tstomapfn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pathprefix</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">fileprefix</span><span class="o">+</span><span class="s">&quot;_tstomap.fits&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tstomapfile</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomapfn</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tstomapfile</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span>

<span class="c">#      self.outfile = open(self.pathprefix+&quot;log_&quot;+self.fileprefix+&quot;_flags.log&quot;,&#39;a&#39;)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsfile</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flagfn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pathprefix</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">fileprefix</span><span class="o">+</span><span class="s">&quot;_flags.fits&quot;</span>
<span class="c">#      if os.path.exists(self.flagfn):</span>
<span class="c">#          self.flagfile = pyfits.open(self.flagfn)</span>
<span class="c">#          self.flags = self.flagfile[0].data</span>
<span class="c">#          if self.flags.shape != self.data.shape:</span>
<span class="c">#              print &quot;Flags / data shape are different.&quot;,self.flags.shape,self.data.shape</span>
<span class="c">#      else:</span>
<span class="c">#          self.flagfile = copy.copy(self.tsfile)</span>
<span class="c">#          self.flags = zeros(self.data.shape,dtype=&#39;int&#39;)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_initialize_vars</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_initialize_vars</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">vmax</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="c">#print &gt;&gt;self.outfile,&quot;Started a new session at &quot;+time.asctime()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">counter</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mouse_up</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">connected</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="c">#self.renderer = matplotlib.backends.backend_agg.RendererAgg</span>
        <span class="k">print</span> <span class="s">&quot;There are </span><span class="si">%i</span><span class="s"> scans&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">maxscan</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">rectangles</span><span class="o">=</span><span class="p">[[]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">maxscan</span><span class="p">)]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lines</span><span class="o">=</span><span class="p">[[]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">maxscan</span><span class="p">)]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span><span class="o">=</span><span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">maparrows</span><span class="o">=</span><span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">connections</span><span class="o">=</span><span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mapconnections</span><span class="o">=</span><span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">md</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mu</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_lastkey</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">scannum</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fignum</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">open</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">currentscan</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">aspect</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span><span class="o">/</span><span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flagfig</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">scanim</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">PCAflag</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">powerspec_plotted</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gaussfit</span><span class="o">=</span><span class="bp">None</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">showmap</span><span class="p">(</span><span class="n">vmax</span><span class="o">=</span><span class="n">vmax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dcon</span><span class="p">()</span>
    
    <span class="k">def</span> <span class="nf">_loadsav</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">savfile</span><span class="p">,</span> <span class="n">flag</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">memtot</span> <span class="o">=</span> <span class="n">heapy</span><span class="o">.</span><span class="n">heap</span><span class="p">()</span><span class="o">.</span><span class="n">size</span> <span class="o">/</span> <span class="mf">1024.0</span><span class="o">**</span><span class="mi">3</span>
        <span class="k">print</span> <span class="s">&quot;Beginning IDLsave file read. </span><span class="si">%0.3g</span><span class="s"> GB used&quot;</span> <span class="o">%</span> <span class="n">memtot</span>
        <span class="n">t0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="n">sav</span> <span class="o">=</span> <span class="n">idlsave</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">savfile</span><span class="p">)</span>
        <span class="n">memtot</span> <span class="o">=</span> <span class="n">heapy</span><span class="o">.</span><span class="n">heap</span><span class="p">()</span><span class="o">.</span><span class="n">size</span> <span class="o">/</span> <span class="mf">1024.0</span><span class="o">**</span><span class="mi">3</span>
        <span class="n">t1</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="k">print</span> <span class="s">&quot;Finished reading IDLsave file in </span><span class="si">%i</span><span class="s"> seconds using </span><span class="si">%0.3g</span><span class="s"> GB&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t1</span> <span class="o">-</span> <span class="n">t0</span><span class="p">,</span><span class="n">memtot</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bgps</span> <span class="o">=</span> <span class="n">sav</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;bgps&#39;</span><span class="p">)</span>
        <span class="n">memtot</span> <span class="o">=</span> <span class="n">heapy</span><span class="o">.</span><span class="n">heap</span><span class="p">()</span><span class="o">.</span><span class="n">size</span> <span class="o">/</span> <span class="mf">1024.0</span><span class="o">**</span><span class="mi">3</span>
        <span class="n">t2</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="k">print</span> <span class="s">&quot;Set bgps variable in </span><span class="si">%i</span><span class="s"> seconds using </span><span class="si">%0.3g</span><span class="s"> GB&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t2</span> <span class="o">-</span> <span class="n">t1</span><span class="p">,</span><span class="n">memtot</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span> <span class="o">=</span> <span class="n">sav</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;mapstr&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span> <span class="o">=</span> <span class="n">sav</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;needed_once_struct&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">neededoncefile</span> <span class="o">=</span> <span class="n">savfile</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;preiter&#39;</span><span class="p">,</span><span class="s">&#39;neededonce&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;postiter&#39;</span><span class="p">,</span><span class="s">&#39;neededonce&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">neededoncefile</span><span class="p">):</span>
                <span class="n">sav_once</span> <span class="o">=</span> <span class="n">idlsave</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">neededoncefile</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span> <span class="o">=</span> <span class="n">sav_once</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;needed_once_struct&#39;</span><span class="p">)</span>
        <span class="n">t3</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="k">print</span> <span class="s">&quot;Completed IDLsave file read in </span><span class="si">%f</span><span class="s"> seconds.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t3</span> <span class="o">-</span> <span class="n">t0</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span> <span class="o">=</span> <span class="n">savfile</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tsfile</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ncdf_filename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span><span class="o">.</span><span class="n">filenames</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">outfile_prefix</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="o">.</span><span class="n">outmap</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">fnsearch</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span>
                <span class="s">&#39;([0-9]{6}_o[0-9b][0-9]_raw_ds[125].nc)(_indiv[0-9]{1,2}pca)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">savfile</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fileprefix</span> <span class="o">=</span> <span class="n">fnsearch</span><span class="o">.</span><span class="n">group</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">pathprefix</span> <span class="o">=</span> <span class="n">savfile</span><span class="p">[:</span><span class="n">fnsearch</span><span class="o">.</span><span class="n">start</span><span class="p">()]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bgps</span><span class="p">[</span><span class="s">&#39;scans_info&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sample_interval</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bgps</span><span class="p">[</span><span class="s">&#39;sample_interval&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="o">.</span><span class="n">shape</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">scanlengths</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="mi">1</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">scanlen</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scanlengths</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ncflags</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bgps</span><span class="p">[</span><span class="s">&#39;flags&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> 
        <span class="bp">self</span><span class="o">.</span><span class="n">timelen</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncflags</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncflags</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nscans</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ncbolo_params</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bgps</span><span class="p">[</span><span class="s">&#39;bolo_params&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ncbolo_indices</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bgps</span><span class="p">[</span><span class="s">&#39;bolo_indices&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="c">#self.bolo_indices = asarray(nonzero(self.ncbolo_params[:,0].ravel())).ravel()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolo_indices</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncbolo_indices</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ngoodbolos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bolo_indices</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">whscan</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">([</span><span class="n">arange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scanlen</span><span class="p">)</span><span class="o">+</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="p">[:,:</span><span class="mi">2</span><span class="p">]])</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">scanstarts</span> <span class="o">=</span> <span class="n">arange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nscans</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">scanlen</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">whempty</span> <span class="o">=</span> <span class="n">concatenate</span><span class="p">([</span><span class="n">arange</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="p">,</span><span class="n">i</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">scanlen</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scanstarts</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">scanlengths</span><span class="p">)</span> <span class="p">])</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">whscan</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">whempty</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">nscans</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">scanlen</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">ngoodbolos</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">datashape</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">nscans</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">scanlen</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">ngoodbolos</span><span class="p">]</span>

        <span class="n">t4</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="n">memtot</span> <span class="o">=</span> <span class="n">heapy</span><span class="o">.</span><span class="n">heap</span><span class="p">()</span><span class="o">.</span><span class="n">size</span> <span class="o">/</span> <span class="mf">1024.0</span><span class="o">**</span><span class="mi">3</span>
        <span class="k">print</span> <span class="s">&quot;Beginning array reshaping with </span><span class="si">%f</span><span class="s"> seconds elapsed, </span><span class="si">%0.3g</span><span class="s"> GB used.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t4</span> <span class="o">-</span> <span class="n">t0</span><span class="p">,</span> <span class="n">memtot</span><span class="p">)</span>

        <span class="c">#class lazy_whscan(object):</span>
        <span class="c">#    class data(object):</span>
        <span class="c">#        def __get__(self, obj, varname, type=None):</span>
        <span class="c">#            print &quot;Computing ... &quot;</span>
        <span class="c">#            obj.__dict__[varname] = self.bgps[varname][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="c">#    data = data()</span>

        <span class="c">#self.flags          = lazydata(&#39;flags&#39;,flag=False) # self.bgps[&#39;flags&#39;][0][self.whscan,:]</span>
        <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="s">&#39;flags&#39;</span><span class="p">,</span> <span class="n">lazydata</span><span class="p">(</span><span class="s">&#39;flags&#39;</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="bp">False</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="o">.</span><span class="n">shape</span>    <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">datashape</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Loading &#39;raw&#39; and &#39;dc_bolos&#39; from needed_once_struct&quot;</span>
            <span class="c">#self.raw         = lazydata(&#39;raw&#39;, &#39;needed_once_struct&#39;) #self.needed_once_struct[&#39;raw&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
            <span class="c">#self.dc_bolos    = lazydata(&#39;dc_bolos&#39;, &#39;needed_once_struct&#39;) #self.needed_once_struct[&#39;dc_bolos&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="s">&#39;raw&#39;</span><span class="p">,</span> <span class="n">lazydata</span><span class="p">(</span><span class="s">&#39;raw&#39;</span><span class="p">,</span> <span class="s">&#39;needed_once_struct&#39;</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="n">flag</span><span class="p">))</span> <span class="c">#self.needed_once_struct[&#39;raw&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="s">&#39;dc_bolos&#39;</span><span class="p">,</span> <span class="n">lazydata</span><span class="p">(</span><span class="s">&#39;dc_bolos&#39;</span><span class="p">,</span> <span class="s">&#39;needed_once_struct&#39;</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="n">flag</span><span class="p">))</span> <span class="c">#self.needed_once_struct[&#39;dc_bolos&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">bgps</span><span class="o">.</span><span class="n">dtype</span><span class="o">.</span><span class="n">fields</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">&#39;raw&#39;</span><span class="p">):</span>
            <span class="k">print</span> <span class="s">&quot;Loading &#39;raw&#39; and &#39;dc_bolos&#39; from bgps&quot;</span>
            <span class="c">#self.raw         = lazydata(&#39;raw&#39;) # self.bgps[&#39;raw&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
            <span class="c">#self.dc_bolos    = lazydata(&#39;dcbolos&#39;) # self.bgps[&#39;dc_bolos&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="s">&#39;raw&#39;</span><span class="p">,</span> <span class="n">lazydata</span><span class="p">(</span><span class="s">&#39;raw&#39;</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="n">flag</span><span class="p">))</span> <span class="c">#self.needed_once_struct[&#39;raw&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="s">&#39;dc_bolos&#39;</span><span class="p">,</span> <span class="n">lazydata</span><span class="p">(</span><span class="s">&#39;dc_bolos&#39;</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="n">flag</span><span class="p">))</span> <span class="c">#self.needed_once_struct[&#39;dc_bolos&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="c">#self.astrosignal    = self.bgps[&#39;astrosignal&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="c">#self.atmosphere     = self.bgps[&#39;atmosphere&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="c">#self.ac_bolos       = self.bgps[&#39;ac_bolos&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="c">#self.atmo_one       = self.bgps[&#39;atmo_one&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="c">#self.noise          = self.bgps[&#39;noise&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="c">#self.scalearr       = self.bgps[&#39;scalearr&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">scale_coeffs</span>   <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bgps</span><span class="p">[</span><span class="s">&#39;scale_coeffs&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s">&#39;float&#39;</span><span class="p">)</span>
        <span class="c">#self.weight         = self.bgps[&#39;weight&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="c">#self.zeromedian     = self.astrosignal * 0</span>
        <span class="n">t5</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="n">memtot</span> <span class="o">=</span> <span class="n">heapy</span><span class="o">.</span><span class="n">heap</span><span class="p">()</span><span class="o">.</span><span class="n">size</span> <span class="o">/</span> <span class="mf">1024.0</span><span class="o">**</span><span class="mi">3</span>
        <span class="k">print</span> <span class="s">&quot;Finished array reshaping in </span><span class="si">%f</span><span class="s"> seconds, </span><span class="si">%0.3g</span><span class="s"> GB used.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t5</span> <span class="o">-</span> <span class="n">t4</span><span class="p">,</span> <span class="n">memtot</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;Beginning array flagging.&quot;</span>

        <span class="c">#try:</span>
        <span class="c">#    self.mapped_astrosignal = self.bgps[&#39;mapped_astrosignal&#39;][0][self.whscan,:].astype(&#39;float&#39;)</span>
        <span class="c">#except ValueError:</span>
        <span class="c">#    self.mapped_astrosignal = copy.copy(self.astrosignal)</span>

        <span class="n">datums</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;astrosignal&#39;</span><span class="p">,</span><span class="s">&#39;atmosphere&#39;</span><span class="p">,</span><span class="s">&#39;ac_bolos&#39;</span><span class="p">,</span><span class="s">&#39;atmo_one&#39;</span><span class="p">,</span><span class="s">&#39;noise&#39;</span><span class="p">,</span><span class="s">&#39;scalearr&#39;</span><span class="p">,</span><span class="s">&#39;weight&#39;</span><span class="p">,</span><span class="s">&#39;mapped_astrosignal&#39;</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">datums</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bgps</span><span class="p">,</span><span class="n">d</span><span class="p">):</span> <span class="c"># for version one, may not have some...</span>
                <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">lazydata</span><span class="p">(</span><span class="n">d</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="n">flag</span><span class="p">))</span>
            <span class="c">#self.__dict__[d] = lazydata(d)</span>
            <span class="c">#if self.__dict__.has_key(d):</span>
            <span class="c">#    self.__dict__[d][self.whempty,:] = NaN</span>
            <span class="c">#    self.__dict__[d].shape = self.datashape</span>
            <span class="c">#    self.__dict__[d] = nantomask(self.__dict__[d])</span>
            <span class="c">#    try:</span>
            <span class="c">#        self.__dict__[d].mask[self.flags &gt; 0] = True</span>
            <span class="c">#    except TypeError:</span>
            <span class="c">#        self.__dict__[d].mask = (self.flags &gt; 0)</span>
        <span class="c">#import pdb; pdb.set_trace()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">weight_by_bolo</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bgps</span><span class="p">,</span><span class="s">&#39;mapped_astrosignal&#39;</span><span class="p">):</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="s">&#39;mapped_astrosignal&#39;</span><span class="p">,</span> <span class="n">lazydata</span><span class="p">(</span><span class="s">&#39;mapped_astrosignal&#39;</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="n">flag</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="s">&#39;mapped_astrosignal&#39;</span><span class="p">,</span> <span class="n">lazydata</span><span class="p">(</span><span class="s">&#39;astrosignal&#39;</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="n">flag</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">:</span>
            <span class="kn">import</span> <span class="nn">pdb</span><span class="p">;</span> <span class="n">pdb</span><span class="o">.</span><span class="n">set_trace</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">ncfile</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flagfn</span> <span class="o">=</span> <span class="n">savfile</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;sav&quot;</span><span class="p">,</span><span class="s">&quot;_flags.fits&quot;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">map</span>      <span class="o">=</span> <span class="n">nantomask</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="p">[</span><span class="s">&#39;astromap&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_map</span> <span class="o">=</span> <span class="n">nantomask</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="p">[</span><span class="s">&#39;astromap&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">model</span>    <span class="o">=</span> <span class="n">nantomask</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="p">[</span><span class="s">&#39;model&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">noisemap</span> <span class="o">=</span> <span class="n">nantomask</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="p">[</span><span class="s">&#39;noisemap&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="p">)</span>
        <span class="c">#setattr(self.__class__, &#39;tstomap&#39;, lazydata(&#39;ts&#39;,reshape=True, structname=&#39;mapstr&#39;))</span>
        <span class="c">#self.tstomap  = lazydata(&#39;ts&#39;,reshape=True) # </span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bgps</span><span class="p">,</span><span class="s">&#39;atmo_one&#39;</span><span class="p">):</span>
            <span class="k">print</span> <span class="s">&quot;Reading file as a v1.0.2 sav file&quot;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapped_timestream</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span> <span class="c"># apparently?</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">scalearr</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">[</span><span class="mi">1</span><span class="p">])[</span><span class="n">newaxis</span><span class="p">,:,</span><span class="n">newaxis</span><span class="p">]</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">scale_coeffs</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)[:,</span><span class="n">newaxis</span><span class="p">,:]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">version</span> <span class="o">=</span> <span class="s">&#39;v1.0&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapped_timestream</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">version</span> <span class="o">=</span> <span class="s">&#39;v2.0&#39;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">map</span>  <span class="o">=</span> <span class="n">nantomask</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="p">[</span><span class="s">&#39;rawmap&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">header</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">Header</span><span class="p">(</span><span class="n">_hdr_string_list_to_cardlist</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="p">[</span><span class="s">&#39;hdr&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="p">))</span>

        <span class="n">t6</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="n">memtot</span> <span class="o">=</span> <span class="n">heapy</span><span class="o">.</span><span class="n">heap</span><span class="p">()</span><span class="o">.</span><span class="n">size</span> <span class="o">/</span> <span class="mf">1024.0</span><span class="o">**</span><span class="mi">3</span>
        <span class="k">print</span> <span class="s">&quot;Finished array flagging in </span><span class="si">%f</span><span class="s"> seconds, </span><span class="si">%0.3g</span><span class="s"> GB used.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t6</span> <span class="o">-</span> <span class="n">t5</span><span class="p">,</span> <span class="n">memtot</span><span class="p">)</span>

        <span class="c"># don&#39;t delay this</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="p">[</span><span class="s">&#39;ts&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="bp">self</span><span class="o">.</span><span class="n">whscan</span><span class="p">,:]</span> <span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">datashape</span> <span class="p">)</span>
        <span class="n">t7</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="n">memtot</span> <span class="o">=</span> <span class="n">heapy</span><span class="o">.</span><span class="n">heap</span><span class="p">()</span><span class="o">.</span><span class="n">size</span> <span class="o">/</span> <span class="mf">1024.0</span><span class="o">**</span><span class="mi">3</span>
        <span class="k">print</span> <span class="s">&quot;Computed tstomap in </span><span class="si">%f</span><span class="s"> seconds, </span><span class="si">%0.3g</span><span class="s"> GB used.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">t7</span> <span class="o">-</span> <span class="n">t6</span><span class="p">,</span> <span class="n">memtot</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_initialize_vars</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">tsplot_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;astrosignal&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">!=</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span>
        <span class="s">&#39;dc_bolos&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">dc_bolos</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">scalearr</span><span class="p">,</span>
        <span class="s">&#39;dc_bolos_noscale&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">dc_bolos</span><span class="p">,</span>
        <span class="s">&#39;dcbolos&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">dc_bolos</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">scalearr</span><span class="p">,</span>
        <span class="s">&#39;dcbolos_noscale&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">dc_bolos</span><span class="p">,</span>
        <span class="s">&#39;acbolos_noscale&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span><span class="p">,</span>
        <span class="s">&#39;ac_bolos_noscale&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span><span class="p">,</span>
        <span class="s">&#39;atmo_one&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span><span class="p">,</span>
        <span class="s">&#39;acbolos&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">scalearr</span><span class="p">,</span>
        <span class="s">&#39;ac_bolos&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">scalearr</span><span class="p">,</span>
        <span class="s">&#39;atmosphere&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span><span class="p">,</span>
        <span class="s">&#39;skysub_noscale&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span><span class="p">,</span>
        <span class="s">&#39;new_astro&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span><span class="p">,</span>
        <span class="s">&#39;new_astro_v1&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;PCA_astro_v1&#39;</span><span class="p">),</span>
        <span class="s">&#39;residual&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">noise</span><span class="p">,</span>
        <span class="s">&#39;skysub&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span><span class="p">,</span>
        <span class="s">&#39;default&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span><span class="p">,</span>
        <span class="s">&#39;last_astrosignal&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">noise</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span><span class="p">,</span>
        <span class="s">&#39;acbMatmo&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span><span class="p">,</span>
        <span class="s">&#39;acbMatmosphere&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span><span class="p">,</span>
        <span class="s">&#39;acbMatmoone&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span><span class="p">,</span>
        <span class="s">&#39;scale&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">scalearr</span><span class="p">,</span>
        <span class="s">&#39;weight&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="p">,</span>
        <span class="s">&#39;raw&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span><span class="p">,</span>
        <span class="s">&#39;rawscaled&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">scalearr</span><span class="p">,</span>
        <span class="s">&#39;noise&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">noise</span><span class="p">,</span>
        <span class="s">&#39;newnoise&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">PCA_astro</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal_from_model</span><span class="p">,</span>
        <span class="s">&#39;mapped_astrosignal&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapped_astrosignal</span><span class="p">,</span>
        <span class="s">&#39;mapped_timestream&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapped_timestream</span><span class="p">,</span>
        <span class="s">&#39;astrosignal_from_map&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">default_map</span><span class="o">.</span><span class="n">flat</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">],</span>
        <span class="s">&#39;astrosignal_from_model&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">flat</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">],</span>
        <span class="s">&#39;itermedian&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">itermedian</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">scalearr</span><span class="p">),</span>
        <span class="s">&#39;zeromedian&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span><span class="p">,</span>
        <span class="s">&#39;atmo_one_itermedian&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">itermedian</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span><span class="p">),</span>
        <span class="s">&#39;expsub&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">exponent_sub</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;atmo_one_itermedian&#39;</span><span class="p">)),</span>
        <span class="s">&#39;atmos_remainder&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;atmo_one_itermedian&#39;</span><span class="p">),</span><span class="c">#self.lookup(&#39;expsub&#39;),</span>
        <span class="s">&#39;atmos_remainder_v1&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">itermedian</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span><span class="p">,</span><span class="n">scale</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span><span class="n">niter</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span>
        <span class="s">&#39;expmodel&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;atmo_one_itermedian&#39;</span><span class="p">)</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;expsub&#39;</span><span class="p">),</span>
        <span class="s">&#39;first_sky&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;atmos_remainder&#39;</span><span class="p">),</span>
        <span class="s">&#39;first_sky_v1&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;atmos_remainder_v1&#39;</span><span class="p">),</span>
        <span class="s">&#39;astrosignal_premap&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;PCA_astro&#39;</span><span class="p">)</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span><span class="p">,</span>
        <span class="s">&#39;PCA_atmo_v1&#39;</span><span class="p">:</span>     <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">unpca_subtract</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">nan_to_num</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;atmos_remainder_v1&#39;</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">npca</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">),</span>
        <span class="s">&#39;PCA_astro_v1&#39;</span><span class="p">:</span>     <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">pca_subtract</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">nan_to_num</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;atmos_remainder_v1&#39;</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">npca</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">),</span>
        <span class="s">&#39;PCA_atmo&#39;</span><span class="p">:</span>     <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">unpca_subtract</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">nan_to_num</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;atmos_remainder&#39;</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">npca</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">),</span>
        <span class="s">&#39;PCA_astro&#39;</span><span class="p">:</span>     <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">pca_subtract</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">nan_to_num</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;atmos_remainder&#39;</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">npca</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">),</span>
        <span class="s">&#39;PCA_astrosignal&#39;</span><span class="p">:</span>   <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">efuncs</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span><span class="o">**</span><span class="mf">0.5</span><span class="p">,</span>
        <span class="s">&#39;PCA_acb&#39;</span><span class="p">:</span>     <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">efuncs</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ac_bolos</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span><span class="o">**</span><span class="mf">0.5</span><span class="p">,</span>
        <span class="s">&#39;PCA_zeromedian&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">efuncs</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span><span class="o">**</span><span class="mf">0.5</span><span class="p">,</span>
        <span class="s">&#39;PCA_itermedian&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">efuncs</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;itermedian&#39;</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span><span class="o">**</span><span class="mf">0.5</span><span class="p">,</span>
        <span class="s">&#39;PCA_noise&#39;</span><span class="p">:</span>   <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">efuncs</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">noise</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span><span class="o">**</span><span class="mf">0.5</span><span class="p">,</span>
        <span class="s">&#39;PCA_default&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">efuncs</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atmo_one</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">atmosphere</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span><span class="o">**</span><span class="mf">0.5</span><span class="p">,</span>
        <span class="s">&#39;PCA_atmos_remainder&#39;</span><span class="p">:</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">reshape</span><span class="p">(</span><span class="n">efuncs</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">nan_to_num</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;atmos_remainder&#39;</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">tsshape</span><span class="p">)),</span><span class="bp">self</span><span class="o">.</span><span class="n">datashape</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span><span class="o">**</span><span class="mf">0.5</span><span class="p">,</span>
        <span class="p">}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">tscache</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">tsplot</span> <span class="o">=</span> <span class="s">&#39;default&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_tsplot</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="k">print</span> <span class="s">&quot;Completed the rest of initialization in an additional </span><span class="si">%f</span><span class="s"> seconds&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">t1</span><span class="p">)</span>

<div class="viewcode-block" id="Flagger.lookup"><a class="viewcode-back" href="../../pyflagger.html#agpy.pyflagger.Flagger.lookup">[docs]</a>    <span class="k">def</span> <span class="nf">lookup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tsname</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Cache and return data...</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">tsname</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tscache</span><span class="p">:</span>
            <span class="n">t0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
            <span class="n">s0</span> <span class="o">=</span> <span class="n">heapy</span><span class="o">.</span><span class="n">heap</span><span class="p">()</span><span class="o">.</span><span class="n">size</span>
            <span class="k">print</span> <span class="s">&quot;Loading and caching </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">tsname</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tscache</span><span class="p">[</span><span class="n">tsname</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot_dict</span><span class="p">[</span><span class="n">tsname</span><span class="p">]()</span>
            <span class="k">print</span> <span class="s">&quot;Loading and caching </span><span class="si">%s</span><span class="s"> took </span><span class="si">%0.2g</span><span class="s"> seconds and ate up </span><span class="si">%0.2g</span><span class="s"> GB&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">tsname</span><span class="p">,</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">t0</span><span class="p">,</span> <span class="p">(</span><span class="n">heapy</span><span class="o">.</span><span class="n">heap</span><span class="p">()</span><span class="o">.</span><span class="n">size</span><span class="o">-</span><span class="n">s0</span><span class="p">)</span><span class="o">/</span><span class="mf">1024.</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">tscache</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">tsname</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="Flagger.set_tsplot"><a class="viewcode-back" href="../../pyflagger.html#agpy.pyflagger.Flagger.set_tsplot">[docs]</a>    <span class="k">def</span> <span class="nf">set_tsplot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">tsplot</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Options: set tsplot equal to one of these strings</span>
<span class="sd">        default = skysub (atmo_one-atmosphere+astrosignal)</span>
<span class="sd">        default_noscale (ac_bolos-atmo_one-atmosphere)</span>
<span class="sd">        residual (atmo_one-atmosphere-noise)</span>
<span class="sd">        last_astrosignal (atmo_one-atmosphere-noise+astrosignal)</span>
<span class="sd">        astrosignal</span>
<span class="sd">        dcbolos</span>
<span class="sd">        acbolos </span>
<span class="sd">        acbolos_noscale </span>
<span class="sd">        atmosphere</span>
<span class="sd">        default_noscale</span>
<span class="sd">        scale</span>
<span class="sd">        raw</span>
<span class="sd">        rawscaled</span>
<span class="sd">        noise</span>
<span class="sd">        zeromedian</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">tsplot</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tsplot</span><span class="o">=</span><span class="n">tsplot</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot_dict</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tsplot</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tsplot</span><span class="p">)</span> <span class="c">#self.tsplot_dict[self.tsplot]()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;No option for </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot</span>
            <span class="k">return</span>
        <span class="k">print</span> <span class="s">&quot;Set tsplot to </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>
</div>
    <span class="k">def</span> <span class="nf">readncfile</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">ncfile</span> <span class="o">=</span> <span class="n">netcdf</span><span class="o">.</span><span class="n">netcdf_file</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span><span class="p">,</span><span class="s">&#39;r&#39;</span><span class="p">)</span> <span class="c"># NetCDF.NetCDFFile(self.ncfilename,&#39;r&#39;)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">ncflags</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfile</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s">&#39;flags&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">ncbolo_params</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfile</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s">&#39;bolo_params&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfile</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s">&#39;scans_info&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">timelen</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncflags</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">scanlen</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">whscan</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">([</span><span class="n">arange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scanlen</span><span class="p">)</span><span class="o">+</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]])</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncflags</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">bolo_indices</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">nonzero</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ncbolo_params</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()))</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">nscans</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
          <span class="n">ft</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncflags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">whscan</span><span class="p">,:]</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">ngoodbolos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bolo_indices</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">(</span><span class="n">ft</span><span class="p">[:,</span><span class="bp">self</span><span class="o">.</span><span class="n">bolo_indices</span><span class="p">],[</span><span class="bp">self</span><span class="o">.</span><span class="n">nscans</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">scanlen</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">ngoodbolos</span><span class="p">])</span>

<div class="viewcode-block" id="Flagger.make_noisemaps"><a class="viewcode-back" href="../../pyflagger.html#agpy.pyflagger.Flagger.make_noisemaps">[docs]</a>    <span class="k">def</span> <span class="nf">make_noisemaps</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">save</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Test a variety of noisemap computations</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">t0</span><span class="o">=</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">residualmap</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="p">[</span><span class="s">&#39;RESIDMAP&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">weightmap</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="p">[</span><span class="s">&#39;WT_MAP&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nhitsmap</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="p">[</span><span class="s">&#39;NHITSMAP&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">residsquaremap</span> <span class="o">=</span> <span class="n">drizzle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">noise</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="o">*</span><span class="p">(</span><span class="bp">True</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">weightsquaremap</span> <span class="o">=</span> <span class="n">drizzle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span><span class="mf">1.0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">varscalemap</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">weightmap</span> <span class="o">/</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weightmap</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">weightsquaremap</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">varscalemap</span><span class="p">[</span><span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weightmap</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">weightsquaremap</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">weightsquaremap</span><span class="o">/</span><span class="mf">1e6</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">rmssamplemean</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">varscalemap</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">residsquaremap</span><span class="p">)</span><span class="o">**</span><span class="mf">0.5</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">rootresidsquaremap</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">residsquaremap</span><span class="o">**</span><span class="mf">0.5</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">smoothresid</span> <span class="o">=</span> <span class="n">smooth</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">residualmap</span><span class="p">,</span><span class="mi">10</span><span class="o">/</span><span class="mf">2.35</span><span class="p">,</span><span class="n">ignore_nan</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">smoothnoisemap</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span> <span class="n">smooth</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">residualmap</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">smoothresid</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span><span class="mi">10</span><span class="o">/</span><span class="mf">2.35</span><span class="p">,</span><span class="n">ignore_nan</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="p">)</span>
        <span class="k">for</span> <span class="n">arrname</span> <span class="ow">in</span> <span class="p">(</span><span class="s">&quot;residualmap&quot;</span><span class="p">,</span> <span class="s">&quot;weightmap&quot;</span><span class="p">,</span> <span class="s">&quot;nhitsmap&quot;</span><span class="p">,</span> <span class="s">&quot;residsquaremap&quot;</span><span class="p">,</span> <span class="s">&quot;weightsquaremap&quot;</span><span class="p">,</span> <span class="s">&quot;varscalemap&quot;</span><span class="p">,</span> <span class="s">&quot;rmssamplemean&quot;</span><span class="p">,</span> <span class="s">&quot;rootresidsquaremap&quot;</span><span class="p">,):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">arrname</span><span class="p">]</span> <span class="o">=</span> <span class="n">nantomask</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">arrname</span><span class="p">])</span>
            <span class="k">print</span> <span class="s">&quot;</span><span class="si">%20s</span><span class="s"> mu=</span><span class="si">%8.2g</span><span class="s"> std=</span><span class="si">%8.2g</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">arrname</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">arrname</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">(),</span><span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">arrname</span><span class="p">]</span><span class="o">.</span><span class="n">std</span><span class="p">())</span>
        <span class="k">print</span> <span class="s">&quot;Took </span><span class="si">%0.1f</span><span class="s"> seconds to compute noisemaps&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">t0</span><span class="p">)</span>
</div>
    <span class="k">def</span> <span class="nf">save_noisemaps</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">clobber</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="n">prefix</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;_postiter.sav&quot;</span><span class="p">,</span><span class="s">&quot;&quot;</span><span class="p">)</span>
        <span class="n">F</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">prefix</span><span class="o">+</span><span class="s">&quot;_map00.fits&quot;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">arrname</span> <span class="ow">in</span> <span class="p">(</span> <span class="s">&quot;residsquaremap&quot;</span><span class="p">,</span> <span class="s">&quot;weightsquaremap&quot;</span><span class="p">,</span> <span class="s">&quot;varscalemap&quot;</span><span class="p">,</span> <span class="s">&quot;rmssamplemean&quot;</span><span class="p">,</span> <span class="s">&quot;rootresidsquaremap&quot;</span><span class="p">,):</span>
            <span class="n">F</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">arrname</span><span class="p">]</span>
            <span class="n">F</span><span class="o">.</span><span class="n">writeto</span><span class="p">(</span><span class="n">prefix</span><span class="o">+</span><span class="s">&quot;_&quot;</span><span class="o">+</span><span class="n">arrname</span><span class="o">+</span><span class="s">&quot;.fits&quot;</span><span class="p">,</span><span class="n">clobber</span><span class="o">=</span><span class="n">clobber</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">showmap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">colormap</span><span class="o">=</span><span class="n">cm</span><span class="o">.</span><span class="n">spectral</span><span class="p">,</span><span class="n">vmin</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">vmax</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">fignum</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">axlims</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">=</span><span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">);</span> <span class="n">clf</span><span class="p">();</span> 
      <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">subplots_adjust</span><span class="p">(</span><span class="n">left</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">right</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span><span class="n">bottom</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">top</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
      <span class="n">OK</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span>
      <span class="k">if</span> <span class="n">vmax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
          <span class="n">vmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">[</span><span class="n">OK</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span><span class="o">+</span><span class="mi">7</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">[</span><span class="n">OK</span><span class="p">]</span><span class="o">.</span><span class="n">std</span><span class="p">()</span>
      <span class="k">elif</span> <span class="n">vmax</span><span class="o">==</span><span class="s">&#39;max&#39;</span><span class="p">:</span>
          <span class="n">vmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">[</span><span class="n">OK</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
      <span class="k">if</span> <span class="n">vmin</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
          <span class="n">vmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">[</span><span class="n">OK</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">[</span><span class="n">OK</span><span class="p">]</span><span class="o">.</span><span class="n">std</span><span class="p">()</span>
      <span class="k">elif</span> <span class="n">vmin</span><span class="o">==</span><span class="s">&#39;min&#39;</span><span class="p">:</span>
          <span class="n">vmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">[</span><span class="n">OK</span><span class="p">]</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mapim</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">,</span>
              <span class="n">vmin</span><span class="o">=</span><span class="n">vmin</span><span class="p">,</span><span class="n">vmax</span><span class="o">=</span><span class="n">vmax</span><span class="p">,</span>
              <span class="n">interpolation</span><span class="o">=</span><span class="s">&#39;nearest&#39;</span><span class="p">,</span>
              <span class="n">cmap</span><span class="o">=</span><span class="n">colormap</span><span class="p">);</span> 
      <span class="bp">self</span><span class="o">.</span><span class="n">mapim</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">patch</span><span class="o">.</span><span class="n">set_fc</span><span class="p">(</span><span class="s">&#39;gray&#39;</span><span class="p">)</span>
      <span class="k">if</span> <span class="n">axlims</span><span class="p">:</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">mapim</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">axis</span><span class="p">(</span><span class="n">axlims</span><span class="p">)</span>
      <span class="n">colorbar</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
          <span class="n">disconnect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoT</span><span class="p">)</span>
          <span class="n">disconnect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoTkey</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
          <span class="k">pass</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">MtoT</span> <span class="o">=</span> <span class="n">connect</span><span class="p">(</span><span class="s">&#39;button_press_event&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mapclick</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">MtoTkey</span> <span class="o">=</span> <span class="n">connect</span><span class="p">(</span><span class="s">&#39;key_press_event&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mapkeypress</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mapcursor</span><span class="o">=</span><span class="n">Cursor</span><span class="p">(</span><span class="n">gca</span><span class="p">(),</span><span class="n">useblit</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mapconnections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoT</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mapconnections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoTkey</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">showmodel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">colormap</span><span class="o">=</span><span class="n">cm</span><span class="o">.</span><span class="n">spectral</span><span class="p">,</span><span class="n">vmin</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">vmax</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">fignum</span><span class="o">=</span><span class="mi">6</span><span class="p">):</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">modelfig</span><span class="o">=</span><span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">);</span> <span class="n">clf</span><span class="p">();</span> 
      <span class="k">if</span> <span class="n">vmax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
          <span class="n">vmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span><span class="o">+</span><span class="mi">7</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">std</span><span class="p">()</span>
      <span class="k">elif</span> <span class="n">vmax</span><span class="o">==</span><span class="s">&#39;max&#39;</span><span class="p">:</span>
          <span class="n">vmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
      <span class="k">if</span> <span class="n">vmin</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
          <span class="n">vmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">std</span><span class="p">()</span>
      <span class="k">elif</span> <span class="n">vmin</span><span class="o">==</span><span class="s">&#39;min&#39;</span><span class="p">:</span>
          <span class="n">vmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">modelim</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">,</span>
              <span class="n">vmin</span><span class="o">=</span><span class="n">vmin</span><span class="p">,</span><span class="n">vmax</span><span class="o">=</span><span class="n">vmax</span><span class="p">,</span>
              <span class="n">interpolation</span><span class="o">=</span><span class="s">&#39;nearest&#39;</span><span class="p">,</span>
              <span class="n">cmap</span><span class="o">=</span><span class="n">colormap</span><span class="p">);</span> 
      <span class="bp">self</span><span class="o">.</span><span class="n">mapim</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">patch</span><span class="o">.</span><span class="n">set_fc</span><span class="p">(</span><span class="s">&#39;gray&#39;</span><span class="p">)</span>
      <span class="n">colorbar</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
          <span class="n">disconnect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoT</span><span class="p">)</span>
          <span class="n">disconnect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoTkey</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
          <span class="k">pass</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">MtoT</span> <span class="o">=</span> <span class="n">connect</span><span class="p">(</span><span class="s">&#39;button_press_event&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mapclick</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">MtoTkey</span> <span class="o">=</span> <span class="n">connect</span><span class="p">(</span><span class="s">&#39;key_press_event&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mapkeypress</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mapcursor</span><span class="o">=</span><span class="n">Cursor</span><span class="p">(</span><span class="n">gca</span><span class="p">(),</span><span class="n">useblit</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mapconnections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoT</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mapconnections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoTkey</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">footprint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">tsx</span><span class="p">,</span><span class="n">tsy</span><span class="p">,</span><span class="n">scatter</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
      <span class="n">mappoints</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">tsy</span><span class="p">,:])</span>

      <span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="o">=</span> <span class="n">mappoints</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">mappoints</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>

      <span class="k">if</span> <span class="n">scatter</span><span class="p">:</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">=</span><span class="n">figure</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">plotmanager</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">get_current_fig_manager</span><span class="p">()</span>
          <span class="n">downsample_factor</span> <span class="o">=</span> <span class="mf">2.</span>
          <span class="k">try</span><span class="p">:</span>
              <span class="n">vals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">tsy</span><span class="p">,:]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
          <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
              <span class="n">vals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">tsy</span><span class="p">,:]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
          <span class="k">try</span><span class="p">:</span>
              <span class="n">flags</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">tsy</span><span class="p">,:]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
          <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
              <span class="n">flags</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">tsy</span><span class="p">,:]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
          <span class="n">flagvals</span> <span class="o">=</span> <span class="n">vals</span><span class="o">*</span><span class="p">(</span><span class="n">flags</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">footim</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">gridmap</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">flagvals</span><span class="p">,</span><span class="n">downsample_factor</span><span class="o">=</span><span class="n">downsample_factor</span><span class="p">,</span><span class="n">xsize</span><span class="o">=</span><span class="mi">72</span><span class="p">,</span><span class="n">ysize</span><span class="o">=</span><span class="mi">72</span><span class="p">)</span>
                  <span class="p">,</span><span class="n">interpolation</span><span class="o">=</span><span class="s">&#39;bilinear&#39;</span><span class="p">,</span><span class="n">extent</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">36</span><span class="o">*</span><span class="mf">7.2</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">36</span><span class="o">*</span><span class="mf">7.2</span><span class="p">])</span>
          <span class="n">pylab</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s">&#39;Arcseconds&#39;</span><span class="p">)</span>
          <span class="n">pylab</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s">&#39;Arcseconds&#39;</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">footcb</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">colorbar</span><span class="p">()</span>
          <span class="k">try</span><span class="p">:</span>
              <span class="bp">self</span><span class="o">.</span><span class="n">footscatter</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="mf">7.2</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="nb">min</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">/</span><span class="n">downsample_factor</span><span class="p">,</span><span class="mf">7.2</span><span class="o">*</span><span class="p">(</span><span class="n">y</span><span class="o">-</span><span class="nb">min</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">/</span><span class="n">downsample_factor</span><span class="p">,</span><span class="n">c</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">tsy</span><span class="p">,:],</span><span class="n">s</span><span class="o">=</span><span class="mi">40</span><span class="p">)</span>

          <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
              <span class="bp">self</span><span class="o">.</span><span class="n">footscatter</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="mf">7.2</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="nb">min</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">/</span><span class="n">downsample_factor</span><span class="p">,</span><span class="mf">7.2</span><span class="o">*</span><span class="p">(</span><span class="n">y</span><span class="o">-</span><span class="nb">min</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">/</span><span class="n">downsample_factor</span><span class="p">,</span><span class="n">c</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">tsy</span><span class="p">,:],</span><span class="n">s</span><span class="o">=</span><span class="mi">40</span><span class="p">)</span>

      <span class="k">else</span><span class="p">:</span>
          <span class="k">try</span><span class="p">:</span>
              <span class="bp">self</span><span class="o">.</span><span class="n">fp2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
              <span class="bp">self</span><span class="o">.</span><span class="n">fp3</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
              <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>
          <span class="k">except</span><span class="p">:</span>
              <span class="k">pass</span>

          <span class="n">figure</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
          <span class="n">myaxis</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">axis</span><span class="p">()</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">fp3</span> <span class="o">=</span> <span class="n">plot</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="s">&#39;ro&#39;</span><span class="p">)</span>
      <span class="c">#    self.fp1 = plot(y,x,&#39;b+&#39;)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">fp2</span> <span class="o">=</span> <span class="n">plot</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="s">&#39;wx&#39;</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">axis</span><span class="p">(</span><span class="n">myaxis</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">bolomap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">bolonum</span><span class="p">):</span>
        <span class="n">bolonum</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">bolonum</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolommap</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolonhits</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolommap</span><span class="o">.</span><span class="n">flat</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">[:,:,</span><span class="n">bolonum</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()]</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[:,:,</span><span class="n">bolonum</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
        <span class="c"># only add hits for non-zero, non-NAN elements</span>
        <span class="n">hits</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[:,:,</span><span class="n">bolonum</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[:,:,</span><span class="n">bolonum</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[:,:,</span><span class="n">bolonum</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolonhits</span><span class="o">.</span><span class="n">flat</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">[:,:,</span><span class="n">bolonum</span><span class="p">]</span><span class="o">.</span><span class="n">ravel</span><span class="p">()]</span> <span class="o">+=</span> <span class="n">hits</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolommap</span> <span class="o">/=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bolonhits</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolomapim</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bolommap</span><span class="p">,</span><span class="n">interpolation</span><span class="o">=</span><span class="s">&#39;nearest&#39;</span><span class="p">,</span><span class="n">origin</span><span class="o">=</span><span class="s">&#39;lower&#39;</span><span class="p">)</span>
        <span class="n">title</span><span class="p">(</span><span class="s">&quot;Bolometer </span><span class="si">%i</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">bolonum</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">disconnect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">gfit_connection</span><span class="p">)</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gfit_connection</span> <span class="o">=</span> <span class="n">connect</span><span class="p">(</span><span class="s">&#39;button_press_event&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">gfit_bolomap</span><span class="p">)</span>
        <span class="n">pylab</span><span class="o">.</span><span class="n">colorbar</span><span class="p">()</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">bolommap</span>

    <span class="k">def</span> <span class="nf">gfit_map</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">event</span><span class="p">,</span><span class="nb">map</span><span class="p">,</span><span class="n">ax</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">ax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">tb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">manager</span><span class="o">.</span><span class="n">toolbar</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">tb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">manager</span><span class="o">.</span><span class="n">toolbar</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&quot;Can&#39;t gaussian fit - no canvas exists?&quot;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span> 
            <span class="n">tb</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">figure</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">manager</span><span class="o">.</span><span class="n">toolbar</span>
        <span class="k">if</span> <span class="n">tb</span><span class="o">.</span><span class="n">mode</span><span class="o">==</span><span class="s">&#39;&#39;</span> <span class="ow">and</span> <span class="n">event</span><span class="o">.</span><span class="n">xdata</span> <span class="ow">and</span> <span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">:</span>
            <span class="n">errmask</span> <span class="o">=</span> <span class="mf">1e10</span> <span class="o">*</span> <span class="n">getmask</span><span class="p">(</span><span class="nb">map</span><span class="p">)</span><span class="o">+</span><span class="mf">1.0</span>
            <span class="n">gf</span> <span class="o">=</span> <span class="n">gaussfitter</span><span class="o">.</span><span class="n">gaussfit</span><span class="p">(</span><span class="n">masktozero</span><span class="p">(</span><span class="nb">map</span><span class="p">),</span>
                    <span class="n">err</span><span class="o">=</span><span class="n">errmask</span><span class="p">,</span>
                    <span class="n">params</span><span class="o">=</span>   <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">,</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span>
                    <span class="n">usemoment</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span>          <span class="mi">0</span><span class="p">,</span>          <span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span>
                    <span class="n">rotate</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">gaussfit</span> <span class="o">=</span> <span class="n">gf</span>
            <span class="k">if</span> <span class="n">ax</span><span class="p">:</span>
                <span class="n">ax</span><span class="o">.</span><span class="n">add_patch</span><span class="p">(</span><span class="n">Ellipse</span><span class="p">(</span><span class="n">gf</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">4</span><span class="p">],</span><span class="n">numpy</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">gf</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">6</span><span class="p">])</span><span class="o">*</span><span class="mf">2.35</span><span class="p">,</span><span class="n">numpy</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">gf</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">6</span><span class="p">])</span><span class="o">*</span><span class="mf">2.35</span><span class="p">,</span><span class="n">gf</span><span class="p">[</span><span class="mi">6</span><span class="p">],</span><span class="n">fill</span><span class="o">=</span><span class="bp">False</span><span class="p">))</span>
            <span class="k">print</span> <span class="s">&quot;Guess: </span><span class="si">%i</span><span class="s">,</span><span class="si">%i</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">,</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">),</span><span class="s">&quot; Fit peak: </span><span class="si">%g</span><span class="s">  Background: </span><span class="si">%g</span><span class="s">  X,Y position: </span><span class="si">%f</span><span class="s">,</span><span class="si">%f</span><span class="s">  X,Y FWHM: </span><span class="si">%f</span><span class="s">,</span><span class="si">%f</span><span class="s">   Angle: </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">gf</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">gf</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">gf</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="n">gf</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span><span class="n">gf</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span><span class="o">*</span><span class="mf">2.35</span><span class="o">*</span><span class="mf">7.2</span><span class="p">,</span><span class="n">gf</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="o">*</span><span class="mf">2.35</span><span class="o">*</span><span class="mf">7.2</span><span class="p">,</span><span class="n">gf</span><span class="p">[</span><span class="mi">6</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">gfit_bolomap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">event</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gfit_map</span><span class="p">(</span><span class="n">event</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">bolommap</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">bolomapim</span><span class="o">.</span><span class="n">axes</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">fiteachbolo</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gfits</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">([</span> <span class="n">gaussfitter</span><span class="o">.</span><span class="n">gaussfit</span><span class="p">(</span><span class="n">masktozero</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bolomap</span><span class="p">(</span><span class="n">bolonum</span><span class="p">)),</span><span class="n">return_all</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="k">for</span> <span class="n">bolonum</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span><span class="p">)])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mapfit</span> <span class="o">=</span> <span class="n">gaussfitter</span><span class="o">.</span><span class="n">gaussfit</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">,</span><span class="n">return_all</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">distmapfig</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">distmapplot</span><span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">errorbar</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">gfits</span><span class="p">[:,</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">]</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">mapfit</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">],</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">gfits</span><span class="p">[:,</span><span class="mi">0</span><span class="p">,</span><span class="mi">3</span><span class="p">]</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">mapfit</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">gfits</span><span class="p">[:,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">],</span><span class="bp">self</span><span class="o">.</span><span class="n">gfits</span><span class="p">[:,</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span><span class="n">fmt</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">capsize</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">gfits</span>

    <span class="k">def</span> <span class="nf">footmovie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">y1</span><span class="p">,</span><span class="n">y2</span><span class="p">,</span><span class="n">movie</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">moviedir</span><span class="o">=</span><span class="s">&#39;scanmovie/&#39;</span><span class="p">,</span><span class="n">logscale</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">dosmooth</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="n">y1</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">y1</span><span class="p">)</span>
        <span class="n">y2</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">y2</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;Making footprint movie from </span><span class="si">%i</span><span class="s"> to </span><span class="si">%i</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">y1</span><span class="p">,</span><span class="n">y2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">footscatter</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
        <span class="c">#if isinstance(self.data,numpy.ma.masked_array):</span>
        <span class="c">#    plotdata = self.data.data</span>
        <span class="c">#    allflags = self.flags.data</span>
        <span class="c">#else:</span>
        <span class="n">plotdata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span>
        <span class="n">allflags</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span>


        <span class="n">mappoints</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="p">,:])</span>
        <span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="o">=</span> <span class="n">mappoints</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">mappoints</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">vals</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span> <span class="n">plotdata</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="p">,:],</span> <span class="p">[</span><span class="nb">abs</span><span class="p">(</span><span class="n">y2</span><span class="o">-</span><span class="n">y1</span><span class="p">),</span><span class="n">plotdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span> <span class="p">)</span>
        <span class="n">flags</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span> <span class="n">allflags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="p">,:],</span> <span class="p">[</span><span class="nb">abs</span><span class="p">(</span><span class="n">y2</span><span class="o">-</span><span class="n">y1</span><span class="p">),</span><span class="n">plotdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span> <span class="p">)</span>
        <span class="n">flagvals</span> <span class="o">=</span> <span class="n">vals</span><span class="o">*</span><span class="p">(</span><span class="n">flags</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">mapcube</span> <span class="o">=</span> <span class="n">array</span><span class="p">([</span> <span class="n">gridmap</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="n">ii</span><span class="p">,:],</span><span class="n">y</span><span class="p">[</span><span class="n">ii</span><span class="p">,:],</span><span class="n">flagvals</span><span class="p">[</span><span class="n">ii</span><span class="p">,:],</span><span class="n">downsample_factor</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span><span class="n">xsize</span><span class="o">=</span><span class="mi">72</span><span class="p">,</span><span class="n">ysize</span><span class="o">=</span><span class="mi">72</span><span class="p">,</span><span class="n">dosmooth</span><span class="o">=</span><span class="n">dosmooth</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">y2</span><span class="o">-</span><span class="n">y1</span><span class="p">)</span> <span class="p">])</span>
        <span class="n">mapcube</span><span class="p">[</span><span class="n">mapcube</span><span class="o">!=</span><span class="n">mapcube</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="k">if</span> <span class="n">logscale</span><span class="p">:</span>
            <span class="c">#mapcube-=mapcube.min()</span>
            <span class="n">mapcube</span><span class="o">=</span><span class="n">numpy</span><span class="o">.</span><span class="n">arcsinh</span><span class="p">(</span><span class="n">mapcube</span><span class="o">/</span><span class="n">logscale</span><span class="p">)</span>
            <span class="c">#self.footim.set_norm(matplotlib.colors.LogNorm())</span>
        <span class="n">vmin</span> <span class="o">=</span> <span class="n">mapcube</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>
        <span class="n">vmax</span> <span class="o">=</span> <span class="n">mapcube</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
        <span class="c">#self.footim.set_clim((vmin,vmax))</span>
        <span class="c">#self.footcb.set_clim((vmin,vmax))</span>
        <span class="c">#self.footim.set_array(mapcube[0,:,:])</span>
        <span class="n">figure</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">footim</span> <span class="o">=</span> <span class="n">imshow</span><span class="p">(</span><span class="n">mapcube</span><span class="p">[</span><span class="mi">0</span><span class="p">,:,:],</span><span class="n">vmin</span><span class="o">=</span><span class="n">vmin</span><span class="p">,</span><span class="n">vmax</span><span class="o">=</span><span class="n">vmax</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">footcb</span><span class="o">.</span><span class="n">ax</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">footcb</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">cax</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">footcb</span><span class="o">.</span><span class="n">ax</span><span class="p">)</span> <span class="c">#self.footim,cax=self.footcb.ax,norm=matplotlib.colors.Normalize(vmin=vmin,vmax=vmax))</span>

        <span class="n">pylab</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">tsy</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">y2</span><span class="o">-</span><span class="n">y1</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">footim</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="n">mapcube</span><span class="p">[</span><span class="n">tsy</span><span class="p">,:,:])</span>
            <span class="c">#self.plotfig.show()</span>
            <span class="c">#pylab.draw()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plotmanager</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">movie</span><span class="p">:</span>
                <span class="n">pylab</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="n">moviedir</span><span class="o">+</span><span class="s">&#39;</span><span class="si">%04i</span><span class="s">.png&#39;</span> <span class="o">%</span> <span class="n">tsy</span><span class="p">)</span>
        
        <span class="k">return</span> <span class="n">mapcube</span>

 
    <span class="k">def</span> <span class="nf">set_plotscan_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">scannum</span><span class="p">,</span><span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">flag</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plane</span> <span class="o">=</span> <span class="n">data</span> <span class="o">*</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">scannum</span><span class="p">,:,:]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plane</span> <span class="o">=</span> <span class="n">data</span>
        <span class="k">elif</span> <span class="n">flag</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plane</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">scannum</span><span class="p">,:,:]</span> <span class="o">*</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">scannum</span><span class="p">,:,:]</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plane</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">scannum</span><span class="p">,:,:]</span> 

    <span class="k">def</span> <span class="nf">plotscan</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scannum</span><span class="p">,</span> <span class="n">fignum</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">button</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">flag</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">logscale</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected</span><span class="p">:</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">dcon</span><span class="p">()</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">scannum</span> <span class="o">=</span> <span class="n">scannum</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">set_plotscan_data</span><span class="p">(</span><span class="n">scannum</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="n">flag</span><span class="p">,</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">fignum</span> <span class="o">=</span> <span class="n">fignum</span>
      <span class="k">if</span> <span class="n">logscale</span><span class="p">:</span>
          <span class="n">plotdata</span> <span class="o">=</span> <span class="n">log10</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">))</span> <span class="o">*</span> <span class="n">sign</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">)</span>
      <span class="k">else</span><span class="p">:</span>
          <span class="n">plotdata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">plane</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">scanim</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">flagfig</span> <span class="o">=</span> <span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">figsize</span><span class="o">=</span><span class="p">[</span><span class="mi">16</span><span class="p">,</span><span class="mi">12</span><span class="p">]);</span> <span class="n">clf</span><span class="p">()</span>
          <span class="k">if</span> <span class="n">texOn</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flagtitle</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">&quot;Flags for Scan &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;_&quot;</span><span class="p">,</span><span class="s">&quot;</span><span class="se">\\</span><span class="s">_&quot;</span><span class="p">));</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flagtitle</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">&quot;Flags for Scan &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span><span class="p">);</span>
          <span class="n">xlabel</span><span class="p">(</span><span class="s">&#39;Bolometer number&#39;</span><span class="p">);</span> <span class="n">ylabel</span><span class="p">(</span><span class="s">&#39;Time (0.</span><span class="si">%0.2f</span><span class="s">s)&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">sample_interval</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">flagim</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">scannum</span><span class="p">,:,:],</span><span class="n">interpolation</span><span class="o">=</span><span class="s">&#39;nearest&#39;</span><span class="p">,</span>
                  <span class="n">origin</span><span class="o">=</span><span class="s">&#39;lower&#39;</span><span class="p">,</span><span class="n">aspect</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">aspect</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">flagcb</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">colorbar</span><span class="p">()</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span> <span class="o">=</span> <span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">,</span><span class="n">figsize</span><span class="o">=</span><span class="p">[</span><span class="mi">16</span><span class="p">,</span><span class="mi">12</span><span class="p">]);</span><span class="n">clf</span><span class="p">();</span>
          <span class="k">if</span> <span class="n">texOn</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">datatitle</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">&quot;Scan &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;_&quot;</span><span class="p">,</span><span class="s">&quot;</span><span class="se">\\</span><span class="s">_&quot;</span><span class="p">));</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">datatitle</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">&quot;Scan &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span><span class="p">);</span>
          <span class="n">xlabel</span><span class="p">(</span><span class="s">&#39;Bolometer number&#39;</span><span class="p">);</span> <span class="n">ylabel</span><span class="p">(</span><span class="s">&#39;Time (0.</span><span class="si">%0.2f</span><span class="s">s)&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">sample_interval</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">dataim</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">plotdata</span><span class="p">,</span><span class="n">interpolation</span><span class="o">=</span><span class="s">&#39;nearest&#39;</span><span class="p">,</span>
                  <span class="n">origin</span><span class="o">=</span><span class="s">&#39;lower&#39;</span><span class="p">,</span><span class="n">aspect</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">aspect</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">datacb</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">colorbar</span><span class="p">()</span>
      <span class="k">else</span><span class="p">:</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">flagim</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">scannum</span><span class="p">,:,:])</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">flagcb</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">cax</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">flagcb</span><span class="o">.</span><span class="n">ax</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">dataim</span><span class="o">.</span><span class="n">set_array</span><span class="p">(</span><span class="n">plotdata</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">datacb</span> <span class="o">=</span> <span class="n">pylab</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">cax</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">datacb</span><span class="o">.</span><span class="n">ax</span><span class="p">)</span>
          <span class="k">if</span> <span class="n">texOn</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flagtitle</span><span class="o">.</span><span class="n">set_text</span><span class="p">(</span><span class="s">&quot;Flags for Scan &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;_&quot;</span><span class="p">,</span><span class="s">&quot;</span><span class="se">\\</span><span class="s">_&quot;</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">datatitle</span><span class="o">.</span><span class="n">set_text</span><span class="p">(</span><span class="s">&quot;Scan &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;_&quot;</span><span class="p">,</span><span class="s">&quot;</span><span class="se">\\</span><span class="s">_&quot;</span><span class="p">))</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flagtitle</span><span class="o">.</span><span class="n">set_text</span><span class="p">(</span><span class="s">&quot;Flags for Scan &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">datatitle</span><span class="o">.</span><span class="n">set_text</span><span class="p">(</span><span class="s">&quot;Scan &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfilename</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">showrects</span><span class="p">()</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">showlines</span><span class="p">()</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">cursor</span> <span class="o">=</span> <span class="n">Cursor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataim</span><span class="o">.</span><span class="n">axes</span><span class="p">,</span><span class="n">useblit</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">reconnect</span><span class="p">()</span>
      <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">      self.md  = connect(&#39;button_press_event&#39;,self.mouse_down_event)</span>
<span class="sd">      self.mu  = connect(&#39;button_release_event&#39;,self.mouse_up_event)</span>
<span class="sd">      self.key = connect(&#39;key_press_event&#39;,self.keypress)</span>
<span class="sd">      self.connections.append(self.md)</span>
<span class="sd">      self.connections.append(self.mu)</span>
<span class="sd">      self.connections.append(self.key)</span>
<span class="sd">      &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">flagpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">button</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">button</span><span class="o">==</span><span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="nb">round</span><span class="p">(</span><span class="n">j</span><span class="p">),</span><span class="nb">round</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="c">#          print &gt;&gt;self.outfile,\</span>
<span class="c">#                  &quot;flag_manual,&#39;%s&#39;,bad_bolos=[%i],bad_time=[[%i,%i]],/doboth&quot;\</span>
<span class="c">#                  % (self.ncfilename,i,self.scannum,j)</span>
        <span class="k">elif</span> <span class="n">button</span><span class="o">==</span><span class="mi">2</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="nb">round</span><span class="p">(</span><span class="n">j</span><span class="p">),</span><span class="nb">round</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span> <span class="o">-=</span>\
                    <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="nb">round</span><span class="p">(</span><span class="n">i</span><span class="p">),</span><span class="nb">round</span><span class="p">(</span><span class="n">j</span><span class="p">)]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
<span class="c">#          print &gt;&gt;self.outfile,\</span>
<span class="c">#                  &quot;undo_flag,&#39;%s&#39;,bad_bolos=[%i],bad_time=[[%i,%i]],/doboth&quot; \</span>
<span class="c">#                  % (self.ncfilename,i,self.scannum,j)</span>
        <span class="k">elif</span> <span class="n">button</span><span class="o">==</span><span class="mi">3</span> <span class="ow">or</span> <span class="n">button</span><span class="o">==</span><span class="s">&#39;d&#39;</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">rectangles</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">get_window_extent</span><span class="p">()</span><span class="o">.</span><span class="n">contains</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">x</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">y</span><span class="p">):</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">rectangles</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
                    <span class="n">x1</span><span class="p">,</span><span class="n">x2</span> <span class="o">=</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_x</span><span class="p">()</span><span class="o">+.</span><span class="mi">5</span><span class="o">*</span><span class="n">sign</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_width</span><span class="p">())</span> <span class="p">,</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">get_x</span><span class="p">()</span><span class="o">-.</span><span class="mi">5</span><span class="o">*</span><span class="n">sign</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_width</span><span class="p">())</span><span class="o">+</span><span class="n">p</span><span class="o">.</span><span class="n">get_width</span><span class="p">()</span> <span class="p">)</span>
                    <span class="n">y1</span><span class="p">,</span><span class="n">y2</span> <span class="o">=</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_y</span><span class="p">()</span><span class="o">+.</span><span class="mi">5</span><span class="o">*</span><span class="n">sign</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_height</span><span class="p">()),</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">get_y</span><span class="p">()</span><span class="o">-.</span><span class="mi">5</span><span class="o">*</span><span class="n">sign</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_height</span><span class="p">())</span><span class="o">+</span><span class="n">p</span><span class="o">.</span><span class="n">get_height</span><span class="p">()</span> <span class="p">)</span>
                    <span class="k">if</span> <span class="n">y1</span> <span class="o">&gt;</span> <span class="n">y2</span><span class="p">:</span>
                      <span class="n">y1</span><span class="p">,</span><span class="n">y2</span><span class="o">=</span><span class="n">y2</span><span class="p">,</span><span class="n">y1</span>
                    <span class="k">if</span> <span class="n">x1</span> <span class="o">&gt;</span> <span class="n">x2</span><span class="p">:</span>
                      <span class="n">x1</span><span class="p">,</span><span class="n">x2</span><span class="o">=</span><span class="n">x2</span><span class="p">,</span><span class="n">x1</span>
                    <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">get_fc</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;black&#39;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-=</span> <span class="p">(</span>
                                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> 
                                <span class="o">*</span> <span class="n">sign</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">])</span> <span class="p">)</span>
                          <span class="c"># only subtract 1 so that overlaps aren&#39;t completely unflagged</span>
                    <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">get_fc</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;blue&#39;</span><span class="p">:</span>
<span class="c">#                      print x1,x2,y1,y2,p.xy,p.get_width(),p.get_height()</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">*=</span> <span class="p">(</span>
                                <span class="o">-</span><span class="mi">1</span><span class="o">*</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> 
                                <span class="o">+</span> <span class="mi">1</span><span class="o">*</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">)</span>
<span class="c">#                  print &gt;&gt;self.outfile,&quot;Removed object with center %f,%f&quot;\</span>
<span class="c">#                          % (p.get_x(),p.get_y())</span>
                    <span class="k">break</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>
 
    <span class="k">def</span> <span class="nf">flag_box</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x1</span><span class="p">,</span><span class="n">y1</span><span class="p">,</span><span class="n">x2</span><span class="p">,</span><span class="n">y2</span><span class="p">,</span><span class="n">button</span><span class="p">):</span>
<span class="c">#      x = (x1+x2)/2.</span>
<span class="c">#      y = (y1+y2)/2.</span>
        <span class="n">x1i</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">x1</span><span class="p">))</span>
        <span class="n">x2i</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">x2</span><span class="p">))</span>
        <span class="n">y1i</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">y1</span><span class="p">))</span>
        <span class="n">y2i</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">y2</span><span class="p">))</span>
        <span class="n">w</span> <span class="o">=</span> <span class="p">(</span><span class="n">x1i</span><span class="o">-</span><span class="n">x2i</span><span class="p">)</span><span class="o">+</span><span class="n">sign</span><span class="p">(</span><span class="n">x1i</span><span class="o">-</span><span class="n">x2i</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">w</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">w</span> <span class="o">=</span> <span class="n">sign</span><span class="p">(</span><span class="n">x1</span><span class="o">-</span><span class="n">x2</span><span class="p">)</span>
        <span class="n">h</span> <span class="o">=</span> <span class="p">(</span><span class="n">y1i</span><span class="o">-</span><span class="n">y2i</span><span class="p">)</span><span class="o">+</span><span class="n">sign</span><span class="p">(</span><span class="n">y1i</span><span class="o">-</span><span class="n">y2i</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">h</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">h</span> <span class="o">=</span> <span class="n">sign</span><span class="p">(</span><span class="n">y1</span><span class="o">-</span><span class="n">y2</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">y1</span><span class="o">==</span><span class="n">y2</span><span class="p">:</span>
            <span class="n">h</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">if</span> <span class="n">x1</span><span class="o">==</span><span class="n">x2</span><span class="p">:</span>
            <span class="n">w</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="n">x2</span> <span class="o">=</span> <span class="n">x2i</span><span class="o">-.</span><span class="mi">5</span><span class="o">*</span><span class="n">sign</span><span class="p">(</span><span class="n">w</span><span class="p">)</span>
        <span class="n">y2</span> <span class="o">=</span> <span class="n">y2i</span><span class="o">-.</span><span class="mi">5</span><span class="o">*</span><span class="n">sign</span><span class="p">(</span><span class="n">h</span><span class="p">)</span>
        <span class="n">x1</span> <span class="o">=</span> <span class="n">x2i</span><span class="o">+</span><span class="n">w</span>
        <span class="n">y1</span> <span class="o">=</span> <span class="n">y2i</span><span class="o">+</span><span class="n">h</span>
        <span class="n">yrange</span> <span class="o">=</span> <span class="p">[</span><span class="nb">min</span><span class="p">(</span><span class="n">y1i</span><span class="p">,</span><span class="n">y2i</span><span class="p">),</span><span class="nb">min</span><span class="p">(</span><span class="n">y1i</span><span class="p">,</span><span class="n">y2i</span><span class="p">)</span><span class="o">+</span><span class="nb">abs</span><span class="p">(</span><span class="n">h</span><span class="p">)]</span>
        <span class="nb">xrange</span> <span class="o">=</span> <span class="p">[</span><span class="nb">min</span><span class="p">(</span><span class="n">x1i</span><span class="p">,</span><span class="n">x2i</span><span class="p">),</span><span class="nb">min</span><span class="p">(</span><span class="n">x1i</span><span class="p">,</span><span class="n">x2i</span><span class="p">)</span><span class="o">+</span><span class="nb">abs</span><span class="p">(</span><span class="n">w</span><span class="p">)]</span>
        <span class="n">scannum</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">scannum</span>
        <span class="k">if</span> <span class="n">button</span><span class="o">==</span><span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">scannum</span><span class="p">,</span><span class="n">yrange</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span><span class="n">yrange</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="nb">xrange</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span><span class="nb">xrange</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">patches</span><span class="o">.</span><span class="n">Rectangle</span><span class="p">(</span><span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="n">x2</span><span class="p">,</span><span class="n">y2</span><span class="p">),</span> <span class="n">width</span><span class="o">=</span><span class="n">w</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="n">h</span><span class="p">,</span>
                    <span class="n">facecolor</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="n">transform</span><span class="o">=</span><span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">transData</span><span class="p">)</span>
            <span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">add_patch</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">set_alpha</span><span class="p">(</span><span class="o">.</span><span class="mi">5</span><span class="p">)</span>
<span class="c">#          self.axis.draw()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rectangles</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>
<span class="c">#          print x,y,w,h,p</span>
<span class="c">#          print &gt;&gt;self.outfile,\</span>
<span class="c">#                  &quot;flag_manual,&#39;%s&#39;,bolorange=[%i,%i],timerange=[%i,%i],scanrange=%i&quot; \</span>
<span class="c">#                  % (self.ncfilename,x1,x2,y1,y2,self.scannum)</span>
        <span class="k">elif</span> <span class="n">button</span><span class="o">==</span><span class="mi">2</span><span class="p">:</span>
           <span class="c"># this won&#39;t work right; I need some way to make it undo-able  </span>
           <span class="c"># &lt;--- I don&#39;t know if that&#39;s true any more (11/10/08)</span>
            <span class="n">unflagreg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">scannum</span><span class="p">,</span><span class="n">yrange</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span><span class="n">yrange</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="nb">xrange</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span><span class="nb">xrange</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> 
            <span class="n">unflagreg</span><span class="p">[</span><span class="n">unflagreg</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">patches</span><span class="o">.</span><span class="n">Rectangle</span><span class="p">(</span><span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="n">x2</span><span class="p">,</span><span class="n">y2</span><span class="p">),</span> <span class="n">width</span><span class="o">=</span><span class="n">w</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="n">h</span><span class="p">,</span>
                    <span class="n">facecolor</span><span class="o">=</span><span class="s">&#39;blue&#39;</span><span class="p">,</span><span class="n">transform</span><span class="o">=</span><span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">transData</span><span class="p">)</span>
            <span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">add_patch</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">set_alpha</span><span class="p">(</span><span class="o">.</span><span class="mi">5</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rectangles</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>
<span class="c">#          print &gt;&gt;self.outfile,\</span>
<span class="c">#                  &quot;undo_flag,&#39;%s&#39;,bolorange=[%i,%i],timerange=[%i,%i],scanrange=%i&quot; \</span>
<span class="c">#                  % (self.ncfilename,x1,x2,y1,y2,self.scannum)</span>
        <span class="k">elif</span> <span class="n">button</span><span class="o">==</span><span class="s">&#39;d&#39;</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">rectangles</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">get_window_extent</span><span class="p">()</span><span class="o">.</span><span class="n">contains</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">x</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">y</span><span class="p">):</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">rectangles</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
                    <span class="n">x1</span><span class="p">,</span><span class="n">x2</span> <span class="o">=</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_x</span><span class="p">()</span><span class="o">+.</span><span class="mi">5</span><span class="o">*</span><span class="n">sign</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_width</span><span class="p">())</span> <span class="p">,</span><span class="n">p</span><span class="o">.</span><span class="n">get_x</span><span class="p">()</span>
                            <span class="o">-.</span><span class="mi">5</span><span class="o">*</span><span class="n">sign</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_width</span><span class="p">())</span><span class="o">+</span><span class="n">p</span><span class="o">.</span><span class="n">get_width</span><span class="p">()</span> <span class="p">)</span> 
                    <span class="n">y1</span><span class="p">,</span><span class="n">y2</span> <span class="o">=</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_y</span><span class="p">()</span><span class="o">+.</span><span class="mi">5</span><span class="o">*</span><span class="n">sign</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_height</span><span class="p">()),</span><span class="n">p</span><span class="o">.</span><span class="n">get_y</span><span class="p">()</span>
                            <span class="o">-.</span><span class="mi">5</span><span class="o">*</span><span class="n">sign</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">get_height</span><span class="p">())</span><span class="o">+</span><span class="n">p</span><span class="o">.</span><span class="n">get_height</span><span class="p">()</span> <span class="p">)</span>
                    <span class="k">if</span> <span class="n">y1</span> <span class="o">&gt;</span> <span class="n">y2</span><span class="p">:</span>
                      <span class="n">y1</span><span class="p">,</span><span class="n">y2</span><span class="o">=</span><span class="n">y2</span><span class="p">,</span><span class="n">y1</span>
                    <span class="k">if</span> <span class="n">x1</span> <span class="o">&gt;</span> <span class="n">x2</span><span class="p">:</span>
                      <span class="n">x1</span><span class="p">,</span><span class="n">x2</span><span class="o">=</span><span class="n">x2</span><span class="p">,</span><span class="n">x1</span>
                    <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">get_fc</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;black&#39;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-=</span> <span class="p">(</span>
                                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> 
                                <span class="o">*</span> <span class="n">sign</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">])</span> <span class="p">)</span>
                          <span class="c"># only subtract 1 so that overlaps aren&#39;t completely unflagged</span>
                    <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">get_fc</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;blue&#39;</span><span class="p">:</span>
<span class="c">#                      print x1,x2,y1,y2,p.xy,p.get_width(),p.get_height()</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">*=</span> <span class="p">(</span>
                                <span class="o">-</span><span class="mi">1</span><span class="o">*</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> 
                                <span class="o">+</span> <span class="mi">1</span><span class="o">*</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">x1</span><span class="p">:</span><span class="n">x2</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">)</span>
<span class="c">#                  print &gt;&gt;self.outfile,&quot;Removed object with center %f,%f&quot;\</span>
<span class="c">#                          % (p.get_x(),p.get_y())</span>
                    <span class="k">break</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">button</span><span class="o">==</span><span class="mi">3</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">maparrow</span><span class="p">(</span><span class="n">x2i</span><span class="p">,</span><span class="n">y2i</span><span class="p">)</span>
 
    <span class="k">def</span> <span class="nf">flag_bolo</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">button</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">button</span><span class="o">==</span><span class="s">&#39;b&#39;</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">PCAflag</span><span class="p">:</span>
            <span class="n">x</span><span class="o">=</span><span class="nb">round</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
            <span class="n">PCAsub</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,:,:]</span> <span class="o">-</span> <span class="n">outer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">[:,</span><span class="n">x</span><span class="p">],</span><span class="n">ones</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">PCAflag</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plotscan</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">data</span><span class="o">=</span><span class="n">PCAsub</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">button</span><span class="o">==</span><span class="s">&#39;b&#39;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">PCAflag</span><span class="p">:</span>
<span class="c">#          print x,round(x),button,self.data.shape</span>
            <span class="n">x</span><span class="o">=</span><span class="nb">round</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
            <span class="n">h</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="n">h</span><span class="p">,</span><span class="n">x</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">lines</span><span class="o">.</span><span class="n">Line2D</span><span class="p">([</span><span class="n">x</span><span class="p">,</span><span class="n">x</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="n">h</span><span class="p">],</span>\
                    <span class="n">color</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="n">transform</span><span class="o">=</span><span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">transData</span><span class="p">)</span>
            <span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">add_line</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">lines</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>
<span class="c">#          print &gt;&gt;self.outfile,\</span>
<span class="c">#                  &quot;flag_manual,&#39;%s&#39;,bolorange=[%i],scanrange=%i&quot; \</span>
<span class="c">#                  % (self.ncfilename,x,self.scannum)</span>

    <span class="k">def</span> <span class="nf">flag_times</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">y1</span><span class="p">,</span><span class="n">y2</span><span class="p">):</span>
        <span class="n">y1</span><span class="o">=</span><span class="nb">max</span><span class="p">([</span><span class="nb">round</span><span class="p">(</span><span class="n">y1</span><span class="p">),</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">y2</span><span class="o">=</span><span class="nb">min</span><span class="p">([</span><span class="nb">round</span><span class="p">(</span><span class="n">y2</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]])</span>
        <span class="n">w</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="n">w</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">p1</span> <span class="o">=</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">lines</span><span class="o">.</span><span class="n">Line2D</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="n">w</span><span class="p">],[</span><span class="n">y1</span><span class="p">,</span><span class="n">y1</span><span class="p">],</span>\
                <span class="n">color</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="n">transform</span><span class="o">=</span><span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">transData</span><span class="p">)</span>
        <span class="n">p2</span> <span class="o">=</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">lines</span><span class="o">.</span><span class="n">Line2D</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="n">w</span><span class="p">],[</span><span class="n">y2</span><span class="p">,</span><span class="n">y2</span><span class="p">],</span>\
                <span class="n">color</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="n">transform</span><span class="o">=</span><span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">transData</span><span class="p">)</span>
        <span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">add_line</span><span class="p">(</span><span class="n">p1</span><span class="p">)</span>
        <span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">add_line</span><span class="p">(</span><span class="n">p2</span><span class="p">)</span>
        <span class="n">p1</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
        <span class="n">p2</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lines</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p1</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lines</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">unflag_times</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">button</span><span class="p">):</span>
        <span class="n">y1</span><span class="o">=</span><span class="nb">max</span><span class="p">([</span><span class="nb">round</span><span class="p">(</span><span class="n">y1</span><span class="p">),</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">y2</span><span class="o">=</span><span class="nb">min</span><span class="p">([</span><span class="nb">round</span><span class="p">(</span><span class="n">y2</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]])</span>
        <span class="n">w</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="n">flagarea</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y1</span><span class="p">:</span><span class="n">y2</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="n">w</span><span class="p">]</span>
        <span class="n">flagarea</span><span class="p">[</span><span class="n">flagarea</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">]</span> <span class="o">-=</span> <span class="mi">1</span>
        <span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="p">(</span><span class="n">y1</span><span class="p">,</span><span class="n">y2</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">lines</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">l</span><span class="o">.</span><span class="n">_y</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">y</span> <span class="ow">and</span> <span class="n">l</span><span class="o">.</span><span class="n">_y</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">y</span><span class="p">:</span>
                    <span class="n">l</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">lines</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">unflag_bolo</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">button</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">button</span><span class="o">==</span><span class="s">&#39;B&#39;</span><span class="p">:</span>
<span class="c">#          print x,round(x),button,self.data.shape</span>
            <span class="n">x</span><span class="o">=</span><span class="nb">round</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
            <span class="n">h</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">lines</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">l</span><span class="o">.</span><span class="n">_x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">x</span> <span class="ow">and</span> <span class="n">l</span><span class="o">.</span><span class="n">_x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">x</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="n">h</span><span class="p">,</span><span class="n">x</span><span class="p">]</span> <span class="o">-=</span> <span class="mi">1</span>
                    <span class="n">l</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">lines</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="n">h</span><span class="p">,</span><span class="n">x</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">arr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="n">h</span><span class="p">,</span><span class="n">x</span><span class="p">]</span>
                <span class="n">arr</span><span class="p">[</span><span class="n">arr</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">]</span> <span class="o">-=</span> <span class="mi">1</span>

    <span class="k">def</span> <span class="nf">plot_column</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">tsx</span><span class="p">,</span><span class="n">clear</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">timestream</span><span class="o">=</span><span class="s">&#39;data&#39;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s">&#39;k&#39;</span><span class="p">,</span> <span class="n">fignum</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span><span class="o">=</span><span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">clear</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">powerspec_plotted</span><span class="p">:</span>
            <span class="n">xlen</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">pylab</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">fftfreq</span><span class="p">(</span><span class="n">xlen</span><span class="p">,</span><span class="n">d</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sample_interval</span><span class="p">)[:</span><span class="n">xlen</span><span class="o">/</span><span class="mi">2</span><span class="p">],</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">[:</span><span class="n">xlen</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">tsx</span><span class="p">)],</span>
                    <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">)</span>
            <span class="n">xlabel</span><span class="p">(</span><span class="s">&quot;Frequency (Hz)&quot;</span><span class="p">)</span>
            <span class="n">ylabel</span><span class="p">(</span><span class="s">&quot;Power (Jy$^2$)&quot;</span><span class="p">)</span>
            <span class="n">title</span><span class="p">(</span><span class="s">&quot;Bolo </span><span class="si">%i</span><span class="s">&quot;</span> <span class="o">%</span> <span class="nb">round</span><span class="p">(</span><span class="n">tsx</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">title</span><span class="p">(</span><span class="s">&quot;Bolo </span><span class="si">%i</span><span class="s">&quot;</span> <span class="o">%</span> <span class="nb">round</span><span class="p">(</span><span class="n">tsx</span><span class="p">))</span>
            <span class="n">xlabel</span><span class="p">(</span><span class="s">&quot;Time Samples&quot;</span><span class="p">)</span>
            <span class="n">ylabel</span><span class="p">(</span><span class="s">&quot;Flux (Jy)&quot;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">timestream</span> <span class="o">==</span> <span class="s">&#39;data&#39;</span><span class="p">:</span>
                <span class="n">pylab</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">[:,</span><span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">tsx</span><span class="p">)],</span>
                        <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">timestream</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                <span class="n">plane</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="n">timestream</span><span class="p">)[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,:,:]</span>
                <span class="n">pylab</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">plane</span><span class="p">[:,</span><span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">tsx</span><span class="p">)],</span>
                        <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">plot_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">tsy</span><span class="p">,</span><span class="n">clear</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">fignum</span><span class="o">=</span><span class="mi">7</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span><span class="o">=</span><span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">clear</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">PCAflag</span><span class="p">:</span>
            <span class="n">pylab</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efuncarr</span><span class="p">[</span><span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">tsy</span><span class="p">),:])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">title</span><span class="p">(</span><span class="s">&quot;Line </span><span class="si">%i</span><span class="s">&quot;</span> <span class="o">%</span> <span class="nb">round</span><span class="p">(</span><span class="n">tsy</span><span class="p">))</span>
            <span class="n">xlabel</span><span class="p">(</span><span class="s">&quot;Bolometer&quot;</span><span class="p">)</span>
            <span class="n">ylabel</span><span class="p">(</span><span class="s">&quot;Flux (Jy)&quot;</span><span class="p">)</span>
            <span class="n">pylab</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">[</span><span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">tsy</span><span class="p">),:])</span>

    <span class="k">def</span> <span class="nf">dcon</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">connected</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="n">disconnect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">md</span><span class="p">)</span>
        <span class="n">disconnect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mu</span><span class="p">)</span>
        <span class="n">disconnect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="p">)</span>
        <span class="n">disconnect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoT</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">connections</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">mpl_disconnect</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">mpl_disconnect</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
            <span class="k">except</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">flagfig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">mpl_disconnect</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
            <span class="k">except</span><span class="p">:</span>
                <span class="k">continue</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapconnections</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">mpl_disconnect</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">reconnect</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">connected</span> <span class="o">=</span> <span class="bp">True</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">MtoT</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">mpl_connect</span><span class="p">(</span><span class="s">&#39;button_press_event&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mapclick</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">MtoTkey</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">mpl_connect</span><span class="p">(</span><span class="s">&#39;key_press_event&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mapkeypress</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">md</span>  <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">mpl_connect</span><span class="p">(</span><span class="s">&#39;button_press_event&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mouse_down_event</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mu</span>  <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">mpl_connect</span><span class="p">(</span><span class="s">&#39;button_release_event&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mouse_up_event</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">mpl_connect</span><span class="p">(</span><span class="s">&#39;key_press_event&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">keypress</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">connections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">md</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">connections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mu</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">connections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mapconnections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoT</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mapconnections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">MtoTkey</span><span class="p">)</span>

<div class="viewcode-block" id="Flagger.close"><a class="viewcode-back" href="../../pyflagger.html#agpy.pyflagger.Flagger.close">[docs]</a>    <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">write</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; close the ncdf file and the graphics windows</span>
<span class="sd">        and flush everything to file&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">open</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
             <span class="bp">self</span><span class="o">.</span><span class="n">open</span> <span class="o">=</span> <span class="mi">0</span>
             <span class="bp">self</span><span class="o">.</span><span class="n">dcon</span><span class="p">()</span>
             <span class="k">if</span> <span class="n">write</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncfile</span><span class="p">:</span>
                 <span class="bp">self</span><span class="o">.</span><span class="n">write_ncdf</span><span class="p">()</span>
             <span class="k">elif</span> <span class="n">write</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">writeflags</span><span class="p">()</span>
<span class="c">#           self.outfile.close()</span>
             <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                 <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
             <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                 <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
             <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                 <span class="bp">self</span><span class="o">.</span><span class="n">bolofig</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
             <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                 <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
             <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">flagfig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                 <span class="bp">self</span><span class="o">.</span><span class="n">flagfig</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
</div>
    <span class="k">def</span> <span class="nf">writeflags</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">flagged_scans</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">ii</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nscans</span><span class="p">)</span> <span class="k">if</span> <span class="nb">all</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">ii</span><span class="p">,:,:])])</span>
        <span class="n">flagged_bolos</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">ii</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span><span class="p">)</span> <span class="k">if</span> <span class="nb">all</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[:,:,</span><span class="n">ii</span><span class="p">])])</span>
        <span class="n">flagged_scans</span><span class="o">.</span><span class="n">tofile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pathprefix</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">fileprefix</span><span class="o">+</span><span class="s">&quot;_flagged_scans.txt&quot;</span><span class="p">,</span><span class="s">&quot; &quot;</span><span class="p">)</span>
        <span class="n">flagged_bolos</span><span class="o">.</span><span class="n">tofile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pathprefix</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">fileprefix</span><span class="o">+</span><span class="s">&quot;_flagged_bolos.txt&quot;</span><span class="p">,</span><span class="s">&quot; &quot;</span><span class="p">)</span>
        <span class="n">tempdata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsfile</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tsfile</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span><span class="n">dtype</span><span class="o">=</span><span class="s">&#39;int&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tsfile</span><span class="o">.</span><span class="n">writeto</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flagfn</span><span class="p">,</span><span class="n">clobber</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tsfile</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">tempdata</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flagfits</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">PrimaryHDU</span><span class="p">(</span><span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span><span class="n">dtype</span><span class="o">=</span><span class="s">&#39;int&#39;</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flagfits</span><span class="o">.</span><span class="n">writeto</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flagfn</span><span class="p">,</span><span class="n">clobber</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
            <span class="k">print</span> <span class="s">&quot;flags_to_ncdf,&#39;</span><span class="si">%s</span><span class="s">&#39;,&#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flagfn</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">idl_writeflags</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">idl_clearflags</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">clearcmd</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;clearflags,&#39;</span><span class="si">%s</span><span class="s">&#39; &amp; &quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span><span class="o">.</span><span class="n">filenames</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
            <span class="n">idlcmd</span> <span class="o">=</span> <span class="s">&quot;/Applications/itt/idl/idl/bin/idl&quot;</span>
            <span class="n">cmd</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s"> -e &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">idlcmd</span><span class="p">,</span><span class="n">clearcmd</span><span class="p">)</span>
            <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s">&quot;IDL_STARTUP&quot;</span><span class="p">:</span><span class="s">&quot;/Users/adam/work/bolocam/.idl_startup_bgps.pro&quot;</span><span class="p">})</span>
            <span class="k">print</span> <span class="n">cmd</span>
            <span class="n">output</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">popen</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
            <span class="k">print</span> <span class="s">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output</span><span class="o">.</span><span class="n">readlines</span><span class="p">())</span>
            <span class="n">output</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">idl_writeflags</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">clearflags</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">override_whgood</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="n">flagcmd</span> <span class="o">=</span> <span class="s">&quot;flags_to_ncdf,&#39;</span><span class="si">%s</span><span class="s">&#39;,&#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flagfn</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">clearflags</span><span class="p">:</span> <span class="n">flagcmd</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;clearflags,&#39;</span><span class="si">%s</span><span class="s">&#39; &amp; &quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span><span class="o">.</span><span class="n">filenames</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span> <span class="o">+</span> <span class="n">flagcmd</span>
        <span class="k">if</span> <span class="n">override_whgood</span><span class="p">:</span> <span class="n">flagcmd</span><span class="o">+=</span><span class="s">&quot;,bolo_indices=</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="s">&quot;[&quot;</span><span class="o">+</span><span class="s">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&quot;</span><span class="si">%i</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">bi</span> <span class="k">for</span> <span class="n">bi</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bolo_indices</span><span class="p">])</span><span class="o">+</span><span class="s">&quot;]&quot;</span><span class="p">)</span>
        <span class="n">idlcmd</span> <span class="o">=</span> <span class="s">&quot;/Applications/itt/idl/idl/bin/idl&quot;</span>
        <span class="n">cmd</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s"> -e &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">idlcmd</span><span class="p">,</span><span class="n">flagcmd</span><span class="p">)</span>
        <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s">&quot;IDL_STARTUP&quot;</span><span class="p">:</span><span class="s">&quot;/Users/adam/work/bolocam/.idl_startup_bgps.pro&quot;</span><span class="p">})</span>
        <span class="k">print</span> <span class="n">cmd</span>
        <span class="n">output</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">popen</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output</span><span class="o">.</span><span class="n">readlines</span><span class="p">())</span>
        <span class="n">output</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">mapclick</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">event</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">xdata</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="n">clickX</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">)</span>
        <span class="n">clickY</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">button</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tsarrow</span><span class="p">(</span><span class="n">clickX</span><span class="p">,</span><span class="n">clickY</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">button</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">find_all_points</span><span class="p">(</span><span class="n">clickX</span><span class="p">,</span><span class="n">clickY</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">button</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">hist_all_points</span><span class="p">(</span><span class="n">clickX</span><span class="p">,</span><span class="n">clickY</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">mapkeypress</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">event</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">inaxes</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> <span class="k">return</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">clickX</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">)</span>
            <span class="n">clickY</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;c&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">toggle_currentscan</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;G&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">gfit_map</span><span class="p">(</span><span class="n">event</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mapim</span><span class="o">.</span><span class="n">axes</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;.&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">xdata</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">return</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">find_all_points</span><span class="p">(</span><span class="n">clickX</span><span class="p">,</span><span class="n">clickY</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tsarrow</span><span class="p">(</span><span class="n">clickX</span><span class="p">,</span><span class="n">clickY</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&quot;r&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">showmap</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;a&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tsarrow</span><span class="p">(</span><span class="n">clickX</span><span class="p">,</span><span class="n">clickY</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;m&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">find_all_points</span><span class="p">(</span><span class="n">clickX</span><span class="p">,</span><span class="n">clickY</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;h&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">hist_all_points</span><span class="p">(</span><span class="n">clickX</span><span class="p">,</span><span class="n">clickY</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">keypress</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">event</span><span class="p">):</span>
        <span class="n">set_lastkey</span><span class="o">=</span><span class="bp">True</span>
        <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">inaxes</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> <span class="k">return</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;n&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">scannum</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">maxscan</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">plotscan</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;At last scan, can&#39;t go further&quot;</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;p&#39;</span> <span class="ow">or</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;N&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">scannum</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">plotscan</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;At first scan, can&#39;t go further back&quot;</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;e&#39;</span><span class="p">:</span> 
            <span class="bp">self</span><span class="o">.</span><span class="n">expsub</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;P&#39;</span><span class="p">:</span> <span class="c"># PCA</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plotscan</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">data</span><span class="o">=</span><span class="n">efuncs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">),</span><span class="n">flag</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">logscale</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">PCAflag</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;q&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;Q&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">write</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;.&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">maparrow</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">),</span><span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">))</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;f&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">footprint</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">),</span><span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">))</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;F&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">footprint</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">),</span><span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">),</span><span class="n">scatter</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;R&#39;</span><span class="p">:</span> <span class="c"># reverse order of boxes</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rectangles</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]</span><span class="o">.</span><span class="n">reverse</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;r&#39;</span><span class="p">:</span> <span class="c"># redraw</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plotscan</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;M&#39;</span><span class="p">:</span> <span class="c"># flag highest point</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,:,:]</span><span class="o">.</span><span class="n">flat</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="o">.</span><span class="n">argmax</span><span class="p">()]</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="o">.</span><span class="n">flat</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="o">.</span><span class="n">argmax</span><span class="p">()]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;m&#39;</span><span class="p">:</span> <span class="c"># flag lowest point</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,:,:]</span><span class="o">.</span><span class="n">flat</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="o">.</span><span class="n">argmin</span><span class="p">()]</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="o">.</span><span class="n">flat</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="o">.</span><span class="n">argmin</span><span class="p">()]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;d&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flag_box</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">y1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">x2</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">y2</span><span class="p">,</span><span class="s">&#39;d&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;t&#39;</span> <span class="ow">or</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;T&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lastkey</span> <span class="o">==</span> <span class="s">&#39;t&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lastkey</span> <span class="o">==</span> <span class="s">&#39;T&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_y2</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;T&#39;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">unflag_times</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_y1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">_y2</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span><span class="s">&#39;t&#39;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">flag_times</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_y1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">_y2</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_lastkey</span> <span class="o">=</span> <span class="bp">None</span>
                <span class="n">set_lastkey</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_y1</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;s&#39;</span> <span class="ow">or</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;w&#39;</span><span class="p">:</span> <span class="c"># &quot;whole&quot; scan</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,:,:]</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;S&#39;</span> <span class="ow">or</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;W&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,:,:]</span> <span class="o">-=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,:,:]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;b&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flag_bolo</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">,</span><span class="n">event</span><span class="o">.</span><span class="n">key</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;B&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">unflag_bolo</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">,</span><span class="n">event</span><span class="o">.</span><span class="n">key</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;c&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">toggle_currentscan</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;C&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plot_column</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;L&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plot_line</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;z&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">powerspec</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;Z&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">powerspec_whole</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;j&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">timestream_whole</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;a&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lastkey</span> <span class="o">==</span> <span class="s">&#39;a&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_y2</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">skymovie</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">footmovie</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_y1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">_y2</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_lastkey</span> <span class="o">=</span> <span class="bp">None</span>
                <span class="n">set_lastkey</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_y1</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">footprint</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">),</span><span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">),</span><span class="n">scatter</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;o&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bolomap</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;v&#39;</span><span class="p">:</span>
            <span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">xdata</span><span class="p">),</span><span class="nb">round</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">ydata</span><span class="p">)</span>
            <span class="n">vpt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">]</span>
            <span class="n">fpt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">]</span>
            <span class="n">xmap</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">ymap</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">]</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">print</span> <span class="s">&quot;Value at </span><span class="si">%i</span><span class="s">,</span><span class="si">%i</span><span class="s">: </span><span class="si">%f</span><span class="s">  Flagged=</span><span class="si">%i</span><span class="s">  Maps to: </span><span class="si">%i</span><span class="s">,</span><span class="si">%i</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">vpt</span><span class="p">,</span><span class="n">fpt</span><span class="p">,</span><span class="n">xmap</span><span class="p">,</span><span class="n">ymap</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">&#39;?&#39;</span><span class="p">:</span>
            <span class="k">print</span> <span class="bp">self</span><span class="o">.</span><span class="n">help</span>
        <span class="k">if</span> <span class="n">set_lastkey</span><span class="p">:</span> 
            <span class="bp">self</span><span class="o">.</span><span class="n">_lastkey</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span>

    <span class="k">def</span> <span class="nf">find_all_points</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">):</span>
        <span class="n">mappoint</span> <span class="o">=</span> <span class="n">y</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">x</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span> <span class="o">=</span>  <span class="n">nonzero</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span> <span class="o">==</span> <span class="n">mappoint</span><span class="p">)</span>
        <span class="n">wtavg</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mapped_timestream</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">]</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">])</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">]</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span>
        <span class="c"># not a real thing wtsclavg = (self.mapped_timestream[self.timepoints]*self.weight[self.timepoints]*self.scalearr[self.timepoints]).sum() / (self.weight[self.timepoints]*self.scalearr[self.timepoints]).sum()</span>
        <span class="n">uwtavg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapped_timestream</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span>
        <span class="n">medavg</span> <span class="o">=</span> <span class="n">median</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mapped_timestream</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">])</span>
        <span class="n">Hmad</span> <span class="o">=</span> <span class="n">MAD</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mapped_timestream</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">])</span>
        <span class="n">Hstd</span> <span class="o">=</span> <span class="n">std</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mapped_timestream</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">])</span>
        <span class="k">print</span> <span class="s">&quot;&quot;</span>
        <span class="k">print</span> <span class="s">&quot;Location: </span><span class="si">%i</span><span class="s">,</span><span class="si">%i</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;Map value: </span><span class="si">%f</span><span class="s">   Weighted average: </span><span class="si">%f</span><span class="s">   Unweighted Average: </span><span class="si">%f</span><span class="s">  Median: </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">[</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">],</span><span class="n">wtavg</span><span class="p">,</span><span class="n">uwtavg</span><span class="p">,</span><span class="n">medavg</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;MAD: </span><span class="si">%f</span><span class="s">   StdDev: </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">Hmad</span><span class="p">,</span><span class="n">Hstd</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;scan,bolo,time: </span><span class="si">%12s%12s%12s%12s%12s%12s%12s%12s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="s">&#39;mapped&#39;</span><span class="p">,</span><span class="s">&#39;mapped_astr&#39;</span><span class="p">,</span><span class="s">&#39;astro&#39;</span><span class="p">,</span><span class="s">&#39;noise&#39;</span><span class="p">,</span><span class="s">&#39;residual&#39;</span><span class="p">,</span><span class="s">&#39;flags&#39;</span><span class="p">,</span><span class="s">&#39;weight&#39;</span><span class="p">,</span><span class="s">&#39;scale&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">ii</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="n">kk</span> <span class="ow">in</span> <span class="n">transpose</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">ii</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="n">kk</span><span class="p">]:</span>
                <span class="k">print</span> <span class="s">&quot;</span><span class="si">%4i</span><span class="s">,</span><span class="si">%4i</span><span class="s">,</span><span class="si">%4i</span><span class="s">: </span><span class="si">%12s%12s%12s%12f%12s%12i%12s%12s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">ii</span><span class="p">,</span><span class="n">kk</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">noisemap</span><span class="p">[</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">],</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">ii</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="n">kk</span><span class="p">],</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="s">&quot;&quot;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;</span><span class="si">%4i</span><span class="s">,</span><span class="si">%4i</span><span class="s">,</span><span class="si">%4i</span><span class="s">: </span><span class="si">%12f%12f%12f%12f%12f%12i%12f%12f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">ii</span><span class="p">,</span><span class="n">kk</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">mapped_timestream</span><span class="p">[</span><span class="n">ii</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="n">kk</span><span class="p">],</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">mapped_astrosignal</span><span class="p">[</span><span class="n">ii</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="n">kk</span><span class="p">],</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">astrosignal</span><span class="p">[</span><span class="n">ii</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="n">kk</span><span class="p">],</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">noisemap</span><span class="p">[</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">],</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">noise</span><span class="p">[</span><span class="n">ii</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="n">kk</span><span class="p">],</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">ii</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="n">kk</span><span class="p">],</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="p">[</span><span class="n">ii</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="n">kk</span><span class="p">],</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">scalearr</span><span class="p">[</span><span class="n">ii</span><span class="p">,</span><span class="n">jj</span><span class="p">,</span><span class="n">kk</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">expsub</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span><span class="p">):</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">,</span><span class="s">&#39;mask&#39;</span><span class="p">):</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="o">.</span><span class="n">mask</span><span class="p">[:,</span><span class="n">ii</span><span class="p">]</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">[:,</span><span class="n">ii</span><span class="p">]</span> <span class="o">=</span> <span class="n">expsub_line</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">[:,</span><span class="n">ii</span><span class="p">])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">[:,</span><span class="n">ii</span><span class="p">]</span> <span class="o">=</span> <span class="n">expsub_line</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">[:,</span><span class="n">ii</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plotscan</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">,</span> <span class="n">flag</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">hist_all_points</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">clear</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">timestream</span><span class="o">=</span><span class="s">&#39;mapped_timestream&#39;</span><span class="p">):</span>
        <span class="n">mappoint</span> <span class="o">=</span> <span class="n">y</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">x</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span> <span class="o">=</span>  <span class="n">nonzero</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span> <span class="o">==</span> <span class="n">mappoint</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">timestream</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">TS</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="n">timestream</span><span class="p">)</span> <span class="c">#tsplot_dict[timestream]()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">KeyError</span><span class="p">(</span><span class="s">&quot;Timestream </span><span class="si">%s</span><span class="s"> is not valid&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">timestream</span><span class="p">))</span>
        <span class="n">wtavg</span> <span class="o">=</span> <span class="p">(</span><span class="n">TS</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">]</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">])</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">]</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span>
        <span class="n">uwtavg</span> <span class="o">=</span> <span class="n">TS</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span>
        <span class="n">medavg</span> <span class="o">=</span> <span class="n">median</span><span class="p">(</span><span class="n">TS</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">])</span>
        <span class="n">Hmad</span> <span class="o">=</span> <span class="n">MAD</span><span class="p">(</span><span class="n">TS</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">])</span>
        <span class="n">Hstd</span> <span class="o">=</span> <span class="n">std</span><span class="p">(</span><span class="n">TS</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">])</span>
        <span class="n">datapts</span> <span class="o">=</span> <span class="n">TS</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="o">==</span><span class="n">mappoint</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">=</span><span class="n">figure</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="n">OK</span>  <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">datapts</span> <span class="o">==</span> <span class="n">datapts</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">datapts</span><span class="p">,</span><span class="s">&#39;mask&#39;</span><span class="p">):</span>
            <span class="n">OK</span> <span class="o">*=</span> <span class="p">(</span><span class="n">datapts</span><span class="o">.</span><span class="n">mask</span> <span class="o">==</span> <span class="bp">False</span><span class="p">)</span>
        <span class="n">n</span><span class="p">,</span><span class="n">bins</span><span class="p">,</span><span class="n">patches</span> <span class="o">=</span> <span class="n">hist</span><span class="p">(</span><span class="n">asarray</span><span class="p">(</span><span class="n">datapts</span><span class="p">[</span><span class="n">OK</span><span class="p">]),</span><span class="n">histtype</span><span class="o">=</span><span class="s">&#39;step&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;k&#39;</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">vlines</span><span class="p">(</span><span class="n">wtavg</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="nb">max</span><span class="p">(</span><span class="n">n</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;k&#39;</span><span class="p">,</span><span class="n">linestyles</span><span class="o">=</span><span class="s">&#39;:&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s">&quot;Weighted: </span><span class="si">%0.4g</span><span class="s"> $</span><span class="se">\\</span><span class="s">pm$ </span><span class="si">%0.4g</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">wtavg</span><span class="p">,</span><span class="n">Hstd</span><span class="p">))</span>
        <span class="c">#vlines(wtavg,0,max(n),color=&#39;k&#39;,linestyles=&#39;:&#39;,label=&quot;Std: %0.4g&quot; % Hstd)</span>
        <span class="n">fill_betweenx</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="nb">max</span><span class="p">(</span><span class="n">n</span><span class="p">)],[</span><span class="n">wtavg</span><span class="o">-</span><span class="n">Hstd</span><span class="p">]</span><span class="o">*</span><span class="mi">2</span><span class="p">,[</span><span class="n">wtavg</span><span class="o">+</span><span class="n">Hstd</span><span class="p">]</span><span class="o">*</span><span class="mi">2</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;k&#39;</span><span class="p">,</span><span class="n">alpha</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s">&quot;Std: </span><span class="si">%0.4g</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">Hstd</span><span class="p">)</span>
        <span class="n">vlines</span><span class="p">(</span><span class="n">uwtavg</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="nb">max</span><span class="p">(</span><span class="n">n</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;b&#39;</span><span class="p">,</span><span class="n">linestyles</span><span class="o">=</span><span class="s">&#39;-.&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s">&quot;Unweighted: </span><span class="si">%0.4g</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">uwtavg</span><span class="p">)</span>
        <span class="n">vlines</span><span class="p">(</span><span class="n">medavg</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="nb">max</span><span class="p">(</span><span class="n">n</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;g&#39;</span><span class="p">,</span><span class="n">linestyles</span><span class="o">=</span><span class="s">&#39;--&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s">&quot;Median: </span><span class="si">%0.4g</span><span class="s"> $</span><span class="se">\\</span><span class="s">pm$ </span><span class="si">%0.4g</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">medavg</span><span class="p">,</span><span class="n">Hmad</span><span class="p">))</span>
        <span class="n">fill_betweenx</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="nb">max</span><span class="p">(</span><span class="n">n</span><span class="p">)],[</span><span class="n">medavg</span><span class="o">-</span><span class="n">Hmad</span><span class="p">]</span><span class="o">*</span><span class="mi">2</span><span class="p">,[</span><span class="n">medavg</span><span class="o">+</span><span class="n">Hmad</span><span class="p">]</span><span class="o">*</span><span class="mi">2</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;g&#39;</span><span class="p">,</span><span class="n">alpha</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s">&quot;MAD: </span><span class="si">%0.4g</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">Hmad</span><span class="p">)</span>
        <span class="n">vlines</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">[</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">],</span><span class="mi">0</span><span class="p">,</span><span class="nb">max</span><span class="p">(</span><span class="n">n</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;purple&#39;</span><span class="p">,</span><span class="n">linestyles</span><span class="o">=</span><span class="s">&#39;--&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s">&quot;Model: </span><span class="si">%0.4g</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">Hmad</span><span class="p">)</span>
        <span class="n">Ctemp</span> <span class="o">=</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">collections</span><span class="o">.</span><span class="n">CircleCollection</span><span class="p">([</span><span class="mi">0</span><span class="p">],</span><span class="n">facecolors</span><span class="o">=</span><span class="s">&#39;k&#39;</span><span class="p">,</span><span class="n">edgecolors</span><span class="o">=</span><span class="s">&#39;k&#39;</span><span class="p">)</span>
        <span class="n">Ctemp</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="s">&#39;Map Value: </span><span class="si">%0.4g</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="p">[</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">]))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">.</span><span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">add_collection</span><span class="p">(</span><span class="n">Ctemp</span><span class="p">)</span>
        <span class="n">L</span><span class="o">=</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="s">&#39;best&#39;</span><span class="p">)</span>
        <span class="n">L</span><span class="o">.</span><span class="n">draggable</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
        <span class="n">title</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> pixel </span><span class="si">%i</span><span class="s">,</span><span class="si">%i</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">))</span>
        <span class="n">xlabel</span><span class="p">(</span><span class="s">&#39;Flux (Jy or Volts)&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">tsarrow</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">debug</span><span class="p">:</span> <span class="k">print</span> <span class="s">&quot;tsarrow at </span><span class="si">%f</span><span class="s">,</span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">)</span>
        <span class="c">#      xy = [clickX,clickY]</span>

        <span class="c"># this took a little thinking:</span>
        <span class="c"># the Y axis has HUGE variation, X has small....</span>
        <span class="n">mappoint</span> <span class="o">=</span> <span class="n">y</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">x</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span> <span class="o">=</span>  <span class="n">nonzero</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span> <span class="o">==</span> <span class="n">mappoint</span><span class="p">)</span>

        <span class="n">matchpts</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">nonzero</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>

<span class="c">#      print mappoint,clickX,clickY,self.timepoints,outer(xy,self.map.shape)</span>
<span class="c">#      for i in outer(xy,self.map.shape).ravel():</span>
<span class="c">#          print i,&quot; :  &quot;,nonzero(self.tstomap==mappoint)</span>

<span class="c">#      print matchpts,mappoint,self.timepoints</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span><span class="p">:</span>
                <span class="n">a</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">matchpts</span><span class="p">):</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">debug</span><span class="p">:</span> <span class="k">print</span> <span class="s">&quot;i shape: &quot;</span><span class="p">,</span><span class="n">i</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="s">&quot; matchpts &quot;</span><span class="p">,</span><span class="n">matchpts</span>
                <span class="n">i</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
                <span class="n">t</span><span class="p">,</span><span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">],</span><span class="bp">self</span><span class="o">.</span><span class="n">timepoints</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
<span class="c">#              print &quot;T,b,i  &quot;,t,b,i</span>
<span class="c">#              print &quot;Does t = []?&quot;,t == []</span>
<span class="c">#              print &quot;Is t &gt;= 0?&quot;,t &gt;= 0</span>
<span class="c">#              arrow = FancyArrow(t-5,b-5,5,5)</span>
<span class="c">#              self.datafig.axes[0].add_patch(arrow)</span>
                <span class="n">figure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fignum</span><span class="p">)</span>
                <span class="n">ax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span><span class="o">.</span><span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="c"># redundant? self.datafig.sca(self.datafig.axes[0])</span>
                <span class="c">#arrow = self.datafig.axes[0].arrow(t-5,b-5,5,5)</span>
                <span class="n">a1</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">arrow</span><span class="p">(</span><span class="n">b</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span><span class="n">t</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="n">head_width</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">facecolor</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">)</span>
                <span class="n">a2</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">arrow</span><span class="p">(</span><span class="n">b</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span><span class="n">t</span><span class="o">+</span><span class="mi">3</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="n">head_width</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">facecolor</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">)</span>
                <span class="n">a1</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
                <span class="n">a2</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
<span class="c">#              print a,t,b</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">a1</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">arrows</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">a2</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">maparrow</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">tsx</span><span class="p">,</span><span class="n">tsy</span><span class="p">):</span>

<span class="c">#    scanpoint = self.scannum*self.flags.shape[1]*self.flags.shape[2]\</span>
          <span class="c">#    + y*self.flags.shape[0] + x</span>
<span class="c">#    print tsx,tsy</span>
      <span class="n">mappoint</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">tsy</span><span class="p">,</span><span class="n">tsx</span><span class="p">]</span>
      <span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="o">=</span> <span class="n">mappoint</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">mappoint</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>

      <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">maparrows</span><span class="p">:</span>
          <span class="n">a</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
      <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">maparrows</span><span class="p">:</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">maparrows</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
      <span class="n">figure</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
      <span class="n">ax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
      <span class="n">a1</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">arrow</span><span class="p">(</span><span class="n">y</span><span class="o">+</span><span class="mi">2</span><span class="p">,</span><span class="n">x</span><span class="o">+</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="n">head_width</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">facecolor</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span>
              <span class="n">length_includes_head</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">head_starts_at_zero</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
      <span class="n">a2</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">arrow</span><span class="p">(</span><span class="n">y</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="n">x</span><span class="o">+</span><span class="mi">2</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="n">head_width</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">facecolor</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span>
              <span class="n">length_includes_head</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">head_starts_at_zero</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
      <span class="n">a1</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
      <span class="n">a2</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">maparrows</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">a1</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">maparrows</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">a2</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_refresh</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">toggle_currentscan</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">currentscan</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">xarr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,:,:]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">yarr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,:,:]</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">x0</span><span class="p">,</span><span class="n">x1</span> <span class="o">=</span> <span class="n">xarr</span><span class="o">.</span><span class="n">min</span><span class="p">(),</span><span class="n">xarr</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
            <span class="n">y0</span><span class="p">,</span><span class="n">y1</span> <span class="o">=</span> <span class="n">yarr</span><span class="o">.</span><span class="n">min</span><span class="p">(),</span><span class="n">yarr</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">axis</span><span class="p">([</span><span class="n">y0</span><span class="p">,</span><span class="n">y1</span><span class="p">,</span><span class="n">x0</span><span class="p">,</span><span class="n">x1</span><span class="p">])</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">currentscan</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapcursor</span><span class="o">=</span><span class="n">Cursor</span><span class="p">(</span><span class="n">gca</span><span class="p">(),</span><span class="n">useblit</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">currentscan</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">axis</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">0</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]])</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">currentscan</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapcursor</span><span class="o">=</span><span class="n">Cursor</span><span class="p">(</span><span class="n">gca</span><span class="p">(),</span><span class="n">useblit</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>


    <span class="k">def</span> <span class="nf">showrects</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">ax</span> <span class="o">=</span> <span class="n">gca</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">rectangles</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">set_transform</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">transData</span><span class="p">)</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">add_patch</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">showlines</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">ax</span> <span class="o">=</span> <span class="n">gca</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">lines</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">]:</span>
            <span class="n">l</span><span class="o">.</span><span class="n">set_transform</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">transData</span><span class="p">)</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">add_line</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>

<div class="viewcode-block" id="Flagger.reset"><a class="viewcode-back" href="../../pyflagger.html#agpy.pyflagger.Flagger.reset">[docs]</a>    <span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
      <span class="sd">&quot;&quot;&quot; Reset flags after the update function is called.</span>
<span class="sd">          Mouse is tracked separately.</span>
<span class="sd">          &quot;&quot;&quot;</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">limits_changed</span> <span class="o">=</span> <span class="mi">0</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">got_draw</span> <span class="o">=</span> <span class="bp">False</span>
</div>
    <span class="k">def</span> <span class="nf">mouse_up_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
      <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">inaxes</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> <span class="k">return</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mouse_up</span> <span class="o">=</span> <span class="bp">True</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">x2</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">xdata</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">y2</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">ydata</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">event</span> <span class="o">=</span> <span class="n">event</span>
      <span class="n">tb</span> <span class="o">=</span> <span class="n">get_current_fig_manager</span><span class="p">()</span><span class="o">.</span><span class="n">toolbar</span>
      <span class="k">if</span> <span class="n">tb</span><span class="o">.</span><span class="n">mode</span><span class="o">==</span><span class="s">&#39;&#39;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">PCAflag</span><span class="p">:</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">flag_box</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">y1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">x2</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">y2</span><span class="p">,</span><span class="n">event</span><span class="o">.</span><span class="n">button</span><span class="p">)</span>
<span class="c">#        if abs(self.x2-self.x1) &gt; 1 or abs(self.y2-self.y1) &gt; 1:</span>
<span class="c">#        else:</span>
<span class="c">#            self.flagpoint(self.x1,self.y1,event.button)</span>

    <span class="k">def</span> <span class="nf">mouse_down_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
      <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">inaxes</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> <span class="k">return</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mouse_up</span> <span class="o">=</span> <span class="bp">False</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">x1</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">xdata</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">y1</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">ydata</span>

    <span class="k">def</span> <span class="nf">powerspec</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">powerspectra</span> <span class="o">=</span> <span class="n">real</span><span class="p">(</span><span class="n">fft</span><span class="p">(</span><span class="n">masktozero</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="o">*</span> <span class="n">conj</span><span class="p">(</span><span class="n">fft</span><span class="p">(</span><span class="n">masktozero</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plane</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plotscan</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">,</span><span class="n">data</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">powerspectra</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">logscale</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="n">ylabel</span><span class="p">(</span><span class="s">&#39;Frequency&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">powerspec_plotted</span> <span class="o">=</span> <span class="bp">True</span>

    <span class="k">def</span> <span class="nf">powerspec_whole</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">bolonum</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">recompute</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">timestream</span><span class="o">=</span><span class="s">&#39;data&#39;</span><span class="p">,</span><span class="n">clear</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">fignum</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span><span class="n">logx</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">logy</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;k&#39;</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">recompute</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">timestream</span> <span class="o">==</span> <span class="s">&#39;data&#39;</span><span class="p">:</span>
                <span class="n">wholedata</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">,[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot_dict</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">timestream</span><span class="p">):</span>
                <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="n">timestream</span><span class="p">)</span> <span class="c">#tsplot_dict[timestream]()</span>
                <span class="n">wholedata</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">(</span><span class="n">data</span><span class="p">,[</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">KeyError</span><span class="p">(</span><span class="s">&quot;Timestream </span><span class="si">%s</span><span class="s"> is not valid.&quot;</span> <span class="o">%</span> <span class="n">timestream</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">wholedata</span><span class="p">,</span><span class="s">&#39;data&#39;</span><span class="p">):</span> <span class="n">wholedata</span> <span class="o">=</span> <span class="n">wholedata</span><span class="o">.</span><span class="n">data</span>
            <span class="n">wholedata</span><span class="p">[</span><span class="n">wholedata</span><span class="o">!=</span><span class="n">wholedata</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span> <span class="o">=</span> <span class="n">real</span><span class="p">(</span><span class="n">fft</span><span class="p">(</span><span class="n">wholedata</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="o">*</span> <span class="n">conj</span><span class="p">(</span><span class="n">fft</span><span class="p">(</span><span class="n">wholedata</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)))</span>
        <span class="n">datashape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">=</span><span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">clear</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">logy</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">logx</span><span class="p">:</span>
                <span class="n">plotcmd</span> <span class="o">=</span> <span class="n">loglog</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">plotcmd</span> <span class="o">=</span> <span class="n">semilogy</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">plotcmd</span> <span class="o">=</span> <span class="n">plot</span>
        <span class="n">plotcmd</span><span class="p">(</span><span class="n">fftfreq</span><span class="p">(</span><span class="n">datashape</span><span class="p">,</span><span class="n">d</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sample_interval</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="n">datashape</span><span class="o">/</span><span class="mi">2</span><span class="p">],</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">datashape</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="n">bolonum</span><span class="p">],</span>
                <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">)</span>
        <span class="n">xlabel</span><span class="p">(</span><span class="s">&quot;Frequency (Hz)&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">broken_powerfit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bolonum</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">plbreak</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">doplot</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">logx</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
            <span class="n">replotspec</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">defaultplot</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">p0in</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">p1in</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">p2in</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">replotspec</span> <span class="ow">or</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">powerspec_whole</span><span class="p">(</span><span class="n">bolonum</span><span class="o">=</span><span class="n">bolonum</span><span class="p">,</span><span class="n">logx</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">datashape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">xfreq</span> <span class="o">=</span> <span class="n">fftfreq</span><span class="p">(</span><span class="n">datashape</span><span class="p">,</span><span class="n">d</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sample_interval</span><span class="p">)[</span><span class="mi">1</span><span class="p">:</span><span class="n">datashape</span><span class="o">/</span><span class="mi">2</span><span class="p">]</span>
        <span class="n">powerspectra_half</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="n">datashape</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="n">bolonum</span><span class="p">]</span>
        <span class="n">p0</span> <span class="o">=</span> <span class="n">polyfit</span><span class="p">(</span><span class="n">log10</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[(</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="mf">0.02</span><span class="p">)]),</span><span class="n">log10</span><span class="p">(</span><span class="n">powerspectra_half</span><span class="p">[(</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="mf">0.02</span><span class="p">)]),</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">p1</span> <span class="o">=</span> <span class="n">polyfit</span><span class="p">(</span><span class="n">log10</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[(</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">xfreq</span><span class="o">&gt;</span><span class="mf">0.02</span><span class="p">)]),</span><span class="n">log10</span><span class="p">(</span><span class="n">powerspectra_half</span><span class="p">[(</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">xfreq</span><span class="o">&gt;</span><span class="mf">0.02</span><span class="p">)]),</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">p2</span> <span class="o">=</span> <span class="n">polyfit</span><span class="p">(</span><span class="n">log10</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">]),</span><span class="n">log10</span><span class="p">(</span><span class="n">powerspectra_half</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">]),</span><span class="mi">1</span><span class="p">)</span>
        <span class="c"># renormalize so that the high-frequency matches the low</span>
        <span class="n">p2nought</span> <span class="o">=</span> <span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">log10</span><span class="p">(</span><span class="mi">10</span><span class="o">**</span><span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">plbreak</span><span class="o">**</span><span class="p">(</span><span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">])))</span>
        <span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">p</span><span class="p">):</span>
            <span class="k">return</span> <span class="mi">10</span><span class="o">**</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">if</span> <span class="bp">None</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="n">p1in</span><span class="p">,</span><span class="n">p2in</span><span class="p">,</span><span class="n">p0in</span><span class="p">):</span>
            <span class="n">plot</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="mf">0.02</span><span class="p">],</span><span class="n">f</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="mf">0.02</span><span class="p">],</span><span class="n">p0in</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">plot</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">],</span><span class="n">f</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">],</span><span class="n">p1in</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">plot</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">],</span><span class="n">f</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">],</span><span class="n">p2in</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;r&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">doplot</span><span class="p">:</span> 
            <span class="n">P</span> <span class="o">=</span> <span class="n">plot</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="mf">0.02</span><span class="p">],</span><span class="n">f</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="mf">0.02</span><span class="p">],</span><span class="n">p0</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">plot</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">],</span><span class="n">f</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">],</span><span class="n">p1</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="n">P</span><span class="o">.</span><span class="n">get_color</span><span class="p">())</span>
            <span class="n">plot</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">],</span><span class="n">f</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">],</span><span class="n">p2</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="n">P</span><span class="o">.</span><span class="n">get_color</span><span class="p">())</span>
        <span class="k">print</span> <span class="s">&quot;Best powerlaw fit: P = 10^</span><span class="si">%0.3f</span><span class="s"> freq^</span><span class="si">%0.3f</span><span class="s">   { freq &lt; </span><span class="si">%0.2f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">plbreak</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;                       10^</span><span class="si">%0.3f</span><span class="s"> freq^</span><span class="si">%0.3f</span><span class="s">   { freq &gt;= </span><span class="si">%0.2f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">plbreak</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;                       10^</span><span class="si">%0.3f</span><span class="s"> freq^</span><span class="si">%0.3f</span><span class="s">   { freq &lt; </span><span class="si">%0.2f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p0</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">p0</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="mf">0.02</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;Reminder: the high-frequency end is forced to meet the low-freqency.  Scale was originally 10^</span><span class="si">%0.3f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p2nought</span><span class="p">)</span>
        <span class="n">noise_scale</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="n">datashape</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span><span class="o">/</span><span class="n">f</span><span class="p">(</span><span class="n">xfreq</span><span class="p">,</span><span class="n">p2</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="mf">2.5</span><span class="p">))[(</span><span class="mi">9</span><span class="o">&gt;</span><span class="n">xfreq</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="mf">2.5</span><span class="p">)]</span><span class="o">.</span><span class="n">std</span><span class="p">()</span>
        <span class="k">print</span> <span class="s">&quot;The Gaussian stddev should be </span><span class="si">%f</span><span class="s"> and the mean should be 1&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">noise_scale</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">p0</span><span class="p">,</span><span class="n">p1</span><span class="p">,</span><span class="n">p2</span><span class="p">,</span><span class="n">noise_scale</span>

<div class="viewcode-block" id="Flagger.broken_expfit"><a class="viewcode-back" href="../../pyflagger.html#agpy.pyflagger.Flagger.broken_expfit">[docs]</a>    <span class="k">def</span> <span class="nf">broken_expfit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">bolonum</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">plbreak</span><span class="o">=</span><span class="mf">2.5</span><span class="p">,</span><span class="n">doplot</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">logx</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">replotspec</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">defaultplot</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Fit two exponentials (one most likely flat) to the power spectrum</span>
<span class="sd">        Ignore frequencies &lt; 0.02 Hz, as these are filtered out by the AC sampler</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">replotspec</span> <span class="ow">or</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">powerspec_whole</span><span class="p">(</span><span class="n">bolonum</span><span class="o">=</span><span class="n">bolonum</span><span class="p">,</span><span class="n">logx</span><span class="o">=</span><span class="n">logx</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">datashape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">xfreq</span> <span class="o">=</span> <span class="n">fftfreq</span><span class="p">(</span><span class="n">datashape</span><span class="p">,</span><span class="n">d</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sample_interval</span><span class="p">)[</span><span class="mi">1</span><span class="p">:</span><span class="n">datashape</span><span class="o">/</span><span class="mi">2</span><span class="p">]</span>
        <span class="n">powerspectra_half</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="n">datashape</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="n">bolonum</span><span class="p">]</span>
        <span class="n">p1</span> <span class="o">=</span> <span class="n">polyfit</span><span class="p">((</span><span class="n">xfreq</span><span class="p">[(</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">xfreq</span><span class="o">&gt;</span><span class="mf">0.02</span><span class="p">)]),</span><span class="n">log10</span><span class="p">(</span><span class="n">powerspectra_half</span><span class="p">[(</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">xfreq</span><span class="o">&gt;</span><span class="mf">0.02</span><span class="p">)]),</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">p2</span> <span class="o">=</span> <span class="n">polyfit</span><span class="p">((</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">]),</span><span class="n">log10</span><span class="p">(</span><span class="n">powerspectra_half</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">]),</span><span class="mi">1</span><span class="p">)</span>
        <span class="c"># renormalize so that the high-frequency matches the low</span>
        <span class="c">#p2nought = p2[1]</span>
        <span class="c">#p2[1] = log10(10**p1[1]*(10**(p1[0]*plbreak-p2[0])))</span>
        <span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">p</span><span class="p">):</span>
            <span class="k">return</span> <span class="mi">10</span><span class="o">**</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">defaultplot</span><span class="p">:</span>
            <span class="n">plot</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">],</span><span class="mi">10</span><span class="o">**</span><span class="mi">4</span><span class="o">*</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">])</span><span class="o">**</span><span class="p">(</span><span class="o">-</span><span class="mf">2.0</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">plot</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">],</span><span class="mf">2.5e3</span><span class="o">*</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">])</span><span class="o">**</span><span class="p">(</span><span class="mf">0.0</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;r&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">doplot</span><span class="p">:</span> 
            <span class="n">P</span> <span class="o">=</span> <span class="n">plot</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">],</span><span class="n">f</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&lt;</span><span class="n">plbreak</span><span class="p">],</span><span class="n">p1</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">plot</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">],</span><span class="n">f</span><span class="p">(</span><span class="n">xfreq</span><span class="p">[</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="n">plbreak</span><span class="p">],</span><span class="n">p2</span><span class="p">),</span><span class="n">color</span><span class="o">=</span><span class="n">P</span><span class="o">.</span><span class="n">get_color</span><span class="p">())</span>
        <span class="k">print</span> <span class="s">&quot;Best powerlaw fit: P = 10^(</span><span class="si">%0.3f</span><span class="s"> nu +</span><span class="si">%0.3f</span><span class="s">)   { freq &lt; </span><span class="si">%0.2f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">plbreak</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;                       10^(</span><span class="si">%0.3f</span><span class="s"> nu +</span><span class="si">%0.3f</span><span class="s">)   { freq &gt;= </span><span class="si">%0.2f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">plbreak</span><span class="p">)</span>
        <span class="n">noise_scale</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">powerspectra_whole</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="n">datashape</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span><span class="o">/</span><span class="n">f</span><span class="p">(</span><span class="n">xfreq</span><span class="p">,</span><span class="n">p2</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="mf">2.5</span><span class="p">))[(</span><span class="mi">9</span><span class="o">&gt;</span><span class="n">xfreq</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">xfreq</span><span class="o">&gt;=</span><span class="mf">2.5</span><span class="p">)]</span><span class="o">.</span><span class="n">std</span><span class="p">()</span>
        <span class="k">print</span> <span class="s">&quot;Therefore the Gaussian stddev should be </span><span class="si">%f</span><span class="s"> and the mean should be 1&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">noise_scale</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">p1</span><span class="p">,</span><span class="n">p2</span><span class="p">,</span><span class="n">noise_scale</span>
</div>
    <span class="k">def</span> <span class="nf">timestream_whole</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">bolonum</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">clear</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">timestream</span><span class="o">=</span><span class="s">&#39;data&#39;</span><span class="p">,</span><span class="n">fignum</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">timestream</span> <span class="o">==</span> <span class="s">&#39;data&#39;</span><span class="p">:</span>
            <span class="n">wholedata</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">,[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot_dict</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">timestream</span><span class="p">):</span>
            <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="n">timestream</span><span class="p">)</span> <span class="c">#tsplot_dict[timestream]()</span>
            <span class="n">wholedata</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">(</span><span class="n">data</span><span class="p">,[</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">KeyError</span><span class="p">(</span><span class="s">&quot;Timestream </span><span class="si">%s</span><span class="s"> is not valid.&quot;</span> <span class="o">%</span> <span class="n">timestream</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">=</span><span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">clear</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">&#39;label&#39;</span><span class="p">):</span>
            <span class="n">label</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;label&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">label</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">bolonum</span><span class="p">)</span>
        <span class="n">plot</span><span class="p">(</span><span class="n">wholedata</span><span class="p">[:,</span><span class="n">bolonum</span><span class="p">],</span><span class="n">linewidth</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>


<div class="viewcode-block" id="Flagger.ordered_timestreams"><a class="viewcode-back" href="../../pyflagger.html#agpy.pyflagger.Flagger.ordered_timestreams">[docs]</a>    <span class="k">def</span> <span class="nf">ordered_timestreams</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>  <span class="n">ordertype</span><span class="o">=</span><span class="s">&#39;astro&#39;</span><span class="p">,</span> <span class="n">clear</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
            <span class="n">colors</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="s">&#39;purple&#39;</span><span class="p">,</span><span class="s">&#39;blue&#39;</span><span class="p">,</span><span class="s">&#39;cyan&#39;</span><span class="p">,</span><span class="s">&#39;green&#39;</span><span class="p">,</span><span class="s">&#39;orange&#39;</span><span class="p">,</span><span class="s">&#39;red&#39;</span><span class="p">,</span><span class="s">&#39;magenta&#39;</span><span class="p">,],</span>
            <span class="n">astro_order</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;ac_bolos&#39;</span><span class="p">,</span><span class="s">&#39;atmo_one&#39;</span><span class="p">,</span><span class="s">&#39;atmo_one_itermedian&#39;</span><span class="p">,</span><span class="s">&#39;atmos_remainder&#39;</span><span class="p">,</span><span class="s">&#39;PCA_astro&#39;</span><span class="p">,</span><span class="s">&#39;astrosignal&#39;</span><span class="p">],</span>
            <span class="n">atmo_order</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;ac_bolos&#39;</span><span class="p">,</span><span class="s">&#39;atmo_one&#39;</span><span class="p">,</span><span class="s">&#39;expmodel&#39;</span><span class="p">,</span><span class="s">&#39;first_sky&#39;</span><span class="p">,</span><span class="s">&#39;PCA_atmo&#39;</span><span class="p">,</span><span class="s">&#39;PCA_astro&#39;</span><span class="p">,</span><span class="s">&#39;noise&#39;</span><span class="p">],</span>
            <span class="n">dolegend</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">dosubplots</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">fignum</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span>
            <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot the timestreams in the order they&#39;re produced during data reduction</span>

<span class="sd">        *ordertype* - &#39;astro&#39; or &#39;atmo&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">ordertype</span><span class="o">==</span><span class="s">&#39;astro&#39;</span><span class="p">:</span>
            <span class="n">order</span> <span class="o">=</span> <span class="n">astro_order</span>
        <span class="k">elif</span> <span class="n">ordertype</span><span class="o">==</span><span class="s">&#39;atmo&#39;</span><span class="p">:</span>
            <span class="n">order</span> <span class="o">=</span> <span class="n">atmo_order</span>

        <span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">)</span>
        <span class="n">clf</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">ii</span><span class="p">,</span><span class="n">tsname</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">order</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">dosubplots</span><span class="p">:</span>
                <span class="n">subplot</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">order</span><span class="p">),</span><span class="mi">1</span><span class="p">,</span><span class="n">ii</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
                <span class="n">title</span><span class="p">(</span><span class="n">tsname</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">timestream_whole</span><span class="p">(</span><span class="n">clear</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">timestream</span><span class="o">=</span><span class="n">tsname</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">tsname</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">colors</span><span class="p">[</span><span class="n">ii</span><span class="p">],</span> <span class="n">fignum</span><span class="o">=</span><span class="n">fignum</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">dolegend</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">dosubplots</span><span class="p">:</span>
            <span class="n">L</span><span class="o">=</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="s">&#39;best&#39;</span><span class="p">)</span>
            <span class="n">L</span><span class="o">.</span><span class="n">draggable</span><span class="p">()</span>
        
    </div>
    <span class="k">def</span> <span class="nf">write_ncdf</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">ncfile</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Not writing NCDF file&quot;</span>
            <span class="k">return</span>

<span class="c">#      flags = asarray(ncfile.variables[&#39;flags&#39;])</span>
<span class="c">#      bolo_params = asarray(ncfile.variables[&#39;bolo_params&#39;])</span>
<span class="c">#      scans_info = asarray(ncfile.variables[&#39;scans_info&#39;])</span>
        <span class="n">flags</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ncflags</span><span class="p">))</span>
        <span class="n">scans_info</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ncscans</span><span class="p">)</span>
        <span class="n">bolo_params</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ncbolo_params</span><span class="p">)</span>
        <span class="n">nbolos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbolos</span>
        <span class="n">scanlen</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">scanlen</span>
        <span class="n">nscans</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nscans</span>
<span class="c">#      self.ngoodbolos = bolo_params[:,0].sum()</span>
        <span class="n">bolo_indices</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bolo_indices</span><span class="p">[</span><span class="n">newaxis</span><span class="p">,:]</span> 
                <span class="o">+</span> <span class="n">zeros</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">whscan</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="mi">1</span><span class="p">])</span> <span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s">&#39;int&#39;</span><span class="p">)</span>
        <span class="n">whscan</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">whscan</span><span class="p">[:,</span><span class="n">newaxis</span><span class="p">]</span> 
                <span class="o">+</span> <span class="n">zeros</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">ngoodbolos</span><span class="p">]))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s">&#39;int&#39;</span><span class="p">)</span>
<span class="c">#      fs= reshape(self.flags,[nscans*scanlen,ngoodbolos])</span>
<span class="c">#      fs2 = zeros([nscans*scanlen,nbolos])</span>
<span class="c">#      fs2[:,self.bolo_indices] = fs</span>
<span class="c">#      flags[self.whscan,:] = fs2</span>
        <span class="n">flags</span><span class="p">[</span><span class="n">whscan</span><span class="p">,</span><span class="n">bolo_indices</span><span class="p">]</span> <span class="o">=</span> <span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span>
                <span class="p">[</span><span class="n">nscans</span><span class="o">*</span><span class="n">scanlen</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">ngoodbolos</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">flags</span><span class="o">.</span><span class="n">min</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
             <span class="n">flags</span><span class="p">[</span><span class="n">flags</span><span class="o">&lt;</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="c">#self.ncfile.close()</span>
        <span class="c">#ncfile = netcdf.netcdf_file(self.ncfilename.replace(&quot;_ds5&quot;,&quot;_ds5_flagged&quot;),&#39;w&#39;) # NetCDF.NetCDFFile(self.ncfilename,&#39;a&#39;)</span>
        <span class="c">#ncfile.variables = self.ncfile.variables</span>
        <span class="c">#ncfile.dimensions = self.ncfile.dimensions</span>
        <span class="n">ncfile</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ncfile</span><span class="p">)</span>
        <span class="n">ncfile</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">ncfile</span><span class="o">.</span><span class="n">filename</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;_ds5&quot;</span><span class="p">,</span><span class="s">&quot;_ds5_flagged&quot;</span><span class="p">)</span>
        <span class="n">ncfile</span><span class="o">.</span><span class="n">fp</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">ncfile</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span><span class="s">&#39;w&#39;</span><span class="p">)</span>
        <span class="n">ncfile</span><span class="o">.</span><span class="n">mode</span> <span class="o">=</span> <span class="s">&#39;w&#39;</span>
        <span class="n">ncfile</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s">&#39;flags&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">flags</span>
        <span class="n">ncfile</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s">&#39;one&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">key</span><span class="p">,</span><span class="n">var</span> <span class="ow">in</span> <span class="n">ncfile</span><span class="o">.</span><span class="n">variables</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> 
            <span class="k">if</span> <span class="n">var</span><span class="o">.</span><span class="n">shape</span> <span class="ow">is</span> <span class="p">():</span>
                <span class="n">var</span><span class="o">.</span><span class="n">dimensions</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;one&#39;</span><span class="p">,)</span>
            <span class="k">if</span> <span class="n">var</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">&#39;file&#39;</span><span class="p">):</span>
                <span class="n">var</span><span class="o">.</span><span class="n">file</span> <span class="o">=</span> <span class="p">(</span><span class="n">var</span><span class="o">.</span><span class="n">file</span><span class="p">,)</span>
            <span class="k">if</span> <span class="n">var</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">&#39;units&#39;</span><span class="p">):</span>
                <span class="n">var</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="p">(</span><span class="n">var</span><span class="o">.</span><span class="n">units</span><span class="p">,)</span>
            <span class="c">#if type(var.data) in (type(1),type(1.0)):</span>
            <span class="c">#    var.data = [var.data]</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span> <span class="ow">in</span> <span class="n">var</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="s">&#39;_shape&#39;</span><span class="p">,</span><span class="s">&#39;_attributes&#39;</span><span class="p">,</span><span class="s">&#39;add_offset&#39;</span><span class="p">,</span><span class="s">&#39;scale_factor&#39;</span><span class="p">):</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">TEMP</span> <span class="o">=</span> <span class="n">v</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="k">except</span><span class="p">:</span>
                        <span class="k">print</span> <span class="s">&quot;Failed at </span><span class="si">%s</span><span class="s"> with value </span><span class="si">%s</span><span class="s"> and type </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span><span class="n">v</span><span class="p">,</span><span class="nb">type</span><span class="p">(</span><span class="n">v</span><span class="p">))</span>
        <span class="n">ncfile</span><span class="o">.</span><span class="n">history</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s"> Flagged on &quot;</span><span class="o">+</span><span class="n">time</span><span class="o">.</span><span class="n">ctime</span><span class="p">()</span>
        <span class="n">ncfile</span><span class="o">.</span><span class="n">_write</span><span class="p">()</span>
<span class="c">#      print ncfile.variables[&#39;flags&#39;].max()</span>
<span class="c">#      import pdb; pdb.set_trace()</span>
        <span class="n">ncfile</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">redraw</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plotscan</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scannum</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_refresh</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">flagfig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">flagfig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">datafig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapfig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plotfig</span><span class="o">.</span><span class="n">canvas</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">PCAflag</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">powerspec_plotted</span> <span class="o">=</span> <span class="bp">False</span>

    <span class="k">def</span> <span class="nf">weightgrid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fignum</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">clear</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wgfig</span> <span class="o">=</span> <span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">clear</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">wgfig</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>

        <span class="n">subplot</span><span class="p">(</span><span class="mi">211</span><span class="p">)</span>
        <span class="n">title</span><span class="p">(</span><span class="s">&quot;Weights&quot;</span><span class="p">)</span>
        <span class="n">imshow</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">weight</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>
        <span class="n">colorbar</span><span class="p">()</span>
        <span class="n">xlabel</span><span class="p">(</span><span class="s">&quot;Bolometer #&quot;</span><span class="p">)</span>
        <span class="n">ylabel</span><span class="p">(</span><span class="s">&quot;Scan #&quot;</span><span class="p">)</span>

        <span class="n">subplot</span><span class="p">(</span><span class="mi">212</span><span class="p">)</span>
        <span class="n">title</span><span class="p">(</span><span class="s">&quot;Scales&quot;</span><span class="p">)</span>
        <span class="n">imshow</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">scalearr</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>
        <span class="n">colorbar</span><span class="p">()</span>
        <span class="n">xlabel</span><span class="p">(</span><span class="s">&quot;Bolometer #&quot;</span><span class="p">)</span>
        <span class="n">ylabel</span><span class="p">(</span><span class="s">&quot;Scan #&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">histograms</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fignum</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span> <span class="n">clear</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">hrange</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">],</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">21</span><span class="p">,</span> <span class="n">dolegend</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
            <span class="n">loc</span><span class="o">=</span><span class="s">&#39;best&#39;</span><span class="p">,</span> <span class="n">ignore_zeros</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">flag</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">histfig</span> <span class="o">=</span> <span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">clear</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">histfig</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">ignore_zeros</span><span class="p">:</span>
            <span class="n">OKscale</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">scale_coeffs</span> <span class="o">!=</span> <span class="mi">0</span>
            <span class="n">OKweight</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">weight_by_bolo</span> <span class="o">!=</span> <span class="mi">0</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">OKscale</span> <span class="o">=</span> <span class="n">OKweight</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">scale_coeffs</span><span class="o">*</span><span class="mi">0</span><span class="o">+</span><span class="bp">True</span>

        <span class="k">if</span> <span class="n">flag</span><span class="p">:</span>
            <span class="c"># lowest flag for a bolometer </span>
            <span class="n">OKflags</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">flags</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span>
            <span class="n">OKscale</span> <span class="o">*=</span> <span class="n">OKflags</span>
            <span class="n">OKweight</span> <span class="o">*=</span> <span class="n">OKflags</span>

        <span class="n">subplot</span><span class="p">(</span><span class="mi">211</span><span class="p">)</span>
        <span class="n">hist</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scale_coeffs</span><span class="p">[</span><span class="n">OKscale</span><span class="p">],</span><span class="n">histtype</span><span class="o">=</span><span class="s">&#39;step&#39;</span><span class="p">,</span><span class="n">bins</span><span class="o">=</span><span class="n">linspace</span><span class="p">(</span><span class="n">hrange</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">hrange</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">nbins</span><span class="p">),</span><span class="n">label</span><span class="o">=</span><span class="s">&#39;Scale Coeffs&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;b&#39;</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">subplot</span><span class="p">(</span><span class="mi">212</span><span class="p">)</span>
        <span class="n">n1</span><span class="p">,</span><span class="n">l1</span><span class="p">,</span><span class="n">h1</span> <span class="o">=</span><span class="n">hist</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weight_by_bolo</span><span class="p">[</span><span class="n">OKweight</span><span class="p">],</span><span class="n">histtype</span><span class="o">=</span><span class="s">&#39;step&#39;</span><span class="p">,</span><span class="n">bins</span><span class="o">=</span><span class="n">nbins</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s">&#39;Weights&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;r&#39;</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">n2</span><span class="p">,</span><span class="n">l2</span><span class="p">,</span><span class="n">h2</span> <span class="o">=</span><span class="n">hist</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="p">[:,:,</span><span class="n">OKweight</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">ravel</span><span class="p">(),</span><span class="n">weights</span><span class="o">=</span><span class="n">ones</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">nscans</span><span class="p">,</span><span class="n">OKweight</span><span class="o">.</span><span class="n">sum</span><span class="p">()))</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">nscans</span><span class="p">,</span><span class="n">histtype</span><span class="o">=</span><span class="s">&#39;step&#39;</span><span class="p">,</span><span class="n">bins</span><span class="o">=</span><span class="n">nbins</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s">&#39;Weights (not avgd. over scans)&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s">&#39;g&#39;</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">max</span><span class="p">([</span><span class="nb">max</span><span class="p">(</span><span class="n">n1</span><span class="p">),</span><span class="nb">max</span><span class="p">(</span><span class="n">n2</span><span class="p">)])</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="n">dolegend</span><span class="p">:</span> <span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="n">loc</span><span class="p">)</span>

<div class="viewcode-block" id="Flagger.unmask_timestream"><a class="viewcode-back" href="../../pyflagger.html#agpy.pyflagger.Flagger.unmask_timestream">[docs]</a>    <span class="k">def</span> <span class="nf">unmask_timestream</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timestream</span><span class="o">=</span><span class="s">&#39;data&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Remove masks for timestream</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">timestream</span> <span class="o">==</span> <span class="s">&#39;data&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">,</span><span class="s">&#39;mask&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">mask</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot_dict</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">timestream</span><span class="p">):</span>
            <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="n">timestream</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">data</span><span class="p">,</span><span class="s">&#39;mask&#39;</span><span class="p">):</span>
                <span class="n">data</span><span class="o">.</span><span class="n">mask</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">False</span>
</div>
    <span class="k">def</span> <span class="nf">unmask_all</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tscache</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tscache</span><span class="p">[</span><span class="n">key</span><span class="p">],</span><span class="s">&#39;mask&#39;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">tscache</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">mask</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">False</span>

    <span class="k">def</span> <span class="nf">clearflags</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">False</span>

        <span class="n">datums</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;astrosignal&#39;</span><span class="p">,</span><span class="s">&#39;atmosphere&#39;</span><span class="p">,</span><span class="s">&#39;ac_bolos&#39;</span><span class="p">,</span><span class="s">&#39;atmo_one&#39;</span><span class="p">,</span><span class="s">&#39;noise&#39;</span><span class="p">,</span><span class="s">&#39;scalearr&#39;</span><span class="p">,</span><span class="s">&#39;weight&#39;</span><span class="p">,</span><span class="s">&#39;mapped_astrosignal&#39;</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">datums</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">d</span><span class="p">):</span>
                <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">d</span><span class="p">]</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">lazydata</span><span class="p">(</span><span class="n">d</span><span class="p">,</span><span class="n">flag</span><span class="o">=</span><span class="bp">False</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">unmask_all</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">doPCA</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">clear</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">timestream</span><span class="o">=</span><span class="s">&#39;data&#39;</span><span class="p">,</span> <span class="n">fignum</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">plotitem</span><span class="o">=</span><span class="s">&#39;evects&#39;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>

        <span class="k">if</span> <span class="n">timestream</span> <span class="o">==</span> <span class="s">&#39;data&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">efuncarr</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">covmat</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">evals</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">evects</span> <span class="o">=</span> <span class="n">efuncs</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">,[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]]),</span><span class="n">return_others</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot_dict</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">timestream</span><span class="p">):</span>
            <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="n">timestream</span><span class="p">)</span> <span class="c">#tsplot_dict[timestream]()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">efuncarr</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">covmat</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">evals</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">evects</span> <span class="o">=</span> <span class="n">efuncs</span><span class="p">(</span><span class="n">reshape</span><span class="p">(</span><span class="n">data</span><span class="p">,[</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]]),</span><span class="n">return_others</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">KeyError</span><span class="p">(</span><span class="s">&quot;Timestream </span><span class="si">%s</span><span class="s"> is not valid.&quot;</span> <span class="o">%</span> <span class="n">timestream</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">PCAfig</span><span class="o">=</span><span class="n">figure</span><span class="p">(</span><span class="n">fignum</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">clear</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">PCAfig</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
      
        <span class="n">plotitem_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;evects&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">evects</span><span class="p">,</span><span class="s">&#39;efuncarr&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">efuncarr</span><span class="p">,</span><span class="s">&#39;covmat&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">covmat</span><span class="p">,</span><span class="s">&#39;evals&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">evals</span><span class="p">}</span>
        <span class="n">plottype_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;evects&#39;</span><span class="p">:</span><span class="n">imshow</span><span class="p">,</span><span class="s">&#39;efuncarr&#39;</span><span class="p">:</span><span class="n">imshow</span><span class="p">,</span><span class="s">&#39;covmat&#39;</span><span class="p">:</span><span class="n">imshow</span><span class="p">,</span><span class="s">&#39;evals&#39;</span><span class="p">:</span><span class="n">plot</span><span class="p">}</span>
        <span class="n">plotkwargs_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;evects&#39;</span><span class="p">:{},</span><span class="s">&#39;efuncarr&#39;</span><span class="p">:{</span><span class="s">&#39;aspect&#39;</span><span class="p">:</span><span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efuncarr</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">efuncarr</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]},</span><span class="s">&#39;covmat&#39;</span><span class="p">:</span><span class="n">imshow</span><span class="p">,</span><span class="s">&#39;evals&#39;</span><span class="p">:</span><span class="n">plot</span><span class="p">}</span>
        <span class="n">xlabel_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;evects&#39;</span><span class="p">:</span><span class="s">&#39;Eigenfunction&#39;</span><span class="p">,</span><span class="s">&#39;efuncarr&#39;</span><span class="p">:</span><span class="s">&#39;Eigenfunction&#39;</span><span class="p">,</span><span class="s">&#39;covmat&#39;</span><span class="p">:</span><span class="s">&#39;Bolometer&#39;</span><span class="p">,</span><span class="s">&#39;evals&#39;</span><span class="p">:</span><span class="s">&#39;Eigenfunction&#39;</span><span class="p">}</span>
        <span class="n">ylabel_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;evects&#39;</span><span class="p">:</span><span class="s">&#39;Bolometer&#39;</span><span class="p">,</span><span class="s">&#39;efuncarr&#39;</span><span class="p">:</span><span class="s">&#39;Time&#39;</span><span class="p">,</span><span class="s">&#39;covmat&#39;</span><span class="p">:</span><span class="s">&#39;Bolometer&#39;</span><span class="p">,</span><span class="s">&#39;evals&#39;</span><span class="p">:</span><span class="s">&#39;Correlation Coefficient&#39;</span><span class="p">}</span>

        <span class="n">plottype_dict</span><span class="p">[</span><span class="n">plotitem</span><span class="p">](</span><span class="n">plotitem_dict</span><span class="p">[</span><span class="n">plotitem</span><span class="p">],</span> <span class="n">label</span><span class="o">=</span><span class="n">plotitem</span><span class="p">,</span> <span class="o">**</span><span class="nb">dict</span><span class="p">(</span><span class="n">plotkwargs_dict</span><span class="p">[</span><span class="n">plotitem</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">(),</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">items</span><span class="p">()))</span>
        <span class="n">xlabel</span><span class="p">(</span><span class="n">xlabel_dict</span><span class="p">[</span><span class="n">plotitem</span><span class="p">])</span>
        <span class="n">ylabel</span><span class="p">(</span><span class="n">ylabel_dict</span><span class="p">[</span><span class="n">plotitem</span><span class="p">])</span>
        <span class="n">colorbar</span><span class="p">()</span>

<div class="viewcode-block" id="Flagger.compute_map"><a class="viewcode-back" href="../../pyflagger.html#agpy.pyflagger.Flagger.compute_map">[docs]</a>    <span class="k">def</span> <span class="nf">compute_map</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">ts</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">tsname</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">weights</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">showmap</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Create a map from the data and potentially show it</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">t0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">ts</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> 
            <span class="k">if</span> <span class="n">tsname</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsplot_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                <span class="n">ts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="n">tsname</span><span class="p">)</span> <span class="c">#tsplot_dict[tsname]()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">ts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapped_timestream</span>
        <span class="k">if</span> <span class="n">weights</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> <span class="n">weights</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">weight</span>
        <span class="k">elif</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">weights</span><span class="p">,</span><span class="n">numpy</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span> <span class="n">weights</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">ts</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span><span class="o">*</span><span class="n">weights</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">map</span> <span class="o">=</span> <span class="n">drizzle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tstomap</span><span class="p">,</span><span class="n">ts</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">map</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span><span class="n">weights</span><span class="o">*</span><span class="p">(</span><span class="bp">True</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">))</span>
        <span class="k">print</span> <span class="s">&quot;Computing map took </span><span class="si">%f</span><span class="s"> seconds&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">t0</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">showmap</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">showmap</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</div>
    <span class="k">def</span> <span class="nf">print_mem_iter</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">outfilename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapstr</span><span class="o">.</span><span class="n">outmap</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">infilename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">needed_once_struct</span><span class="o">.</span><span class="n">filenames</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

            <span class="n">command</span> <span class="o">=</span> <span class="s">&quot;mem_iter,&#39;{infile}&#39;,&#39;{outfile}&#39;,/no_offsets,/pointing_model,niter=[13,13],dosave=2&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">outfile</span><span class="o">=</span><span class="n">outfilename</span><span class="p">,</span><span class="n">infile</span><span class="o">=</span><span class="n">infilename</span><span class="p">)</span>

            <span class="k">print</span> <span class="n">command</span>
            <span class="k">return</span> <span class="n">command</span>

</div>
<span class="k">def</span> <span class="nf">nantomask</span><span class="p">(</span><span class="n">arr</span><span class="p">):</span>
      <span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">arr</span> <span class="o">!=</span> <span class="n">arr</span><span class="p">)</span>
      <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ma</span><span class="o">.</span><span class="n">masked_where</span><span class="p">(</span><span class="n">mask</span><span class="p">,</span><span class="n">arr</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">masktozero</span><span class="p">(</span><span class="n">arr</span><span class="p">):</span>
      <span class="k">try</span><span class="p">:</span>
          <span class="n">arr</span><span class="p">[</span><span class="n">arr</span><span class="o">.</span><span class="n">mask</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
      <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
          <span class="n">arr</span><span class="p">[</span><span class="n">arr</span><span class="o">!=</span><span class="n">arr</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
      <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">getmask</span><span class="p">(</span><span class="n">arr</span><span class="p">):</span>
      <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span><span class="s">&#39;mask&#39;</span><span class="p">):</span>
          <span class="k">return</span> <span class="n">arr</span><span class="o">.</span><span class="n">mask</span>
      <span class="k">else</span><span class="p">:</span>
          <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">arr</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">downsample</span><span class="p">(</span><span class="n">myarr</span><span class="p">,</span><span class="n">factor</span><span class="p">):</span>
      <span class="n">factor</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
      <span class="n">xs</span><span class="p">,</span><span class="n">ys</span> <span class="o">=</span> <span class="n">myarr</span><span class="o">.</span><span class="n">shape</span>
      <span class="n">crarr</span> <span class="o">=</span> <span class="n">myarr</span><span class="p">[:</span><span class="n">xs</span><span class="o">-</span><span class="p">(</span><span class="n">xs</span> <span class="o">%</span> <span class="nb">int</span><span class="p">(</span><span class="n">factor</span><span class="p">)),:</span><span class="n">ys</span><span class="o">-</span><span class="p">(</span><span class="n">ys</span> <span class="o">%</span> <span class="nb">int</span><span class="p">(</span><span class="n">factor</span><span class="p">))]</span>
      <span class="n">dsarr</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([[</span><span class="n">crarr</span><span class="p">[</span><span class="n">i</span><span class="p">::</span><span class="n">factor</span><span class="p">,</span><span class="n">j</span><span class="p">::</span><span class="n">factor</span><span class="p">]</span>
          <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">factor</span><span class="p">)]</span>
          <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">factor</span><span class="p">)])</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
      <span class="k">return</span> <span class="n">dsarr</span> 

<span class="k">def</span> <span class="nf">gridmap</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">v</span><span class="p">,</span><span class="n">downsample_factor</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span><span class="n">smoothpix</span><span class="o">=</span><span class="mf">3.0</span><span class="p">,</span><span class="n">dosmooth</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">xsize</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">ysize</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
      <span class="n">nx</span> <span class="o">=</span> <span class="nb">xrange</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">-</span><span class="n">numpy</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">x</span><span class="p">))</span><span class="o">+</span><span class="mi">3</span>
      <span class="n">ny</span> <span class="o">=</span> <span class="n">yrange</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">-</span><span class="n">numpy</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">y</span><span class="p">))</span><span class="o">+</span><span class="mi">3</span>
      <span class="n">xax</span> <span class="o">=</span> <span class="n">x</span><span class="o">-</span><span class="nb">min</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
      <span class="n">yax</span> <span class="o">=</span> <span class="n">y</span><span class="o">-</span><span class="nb">min</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
      <span class="k">if</span> <span class="n">xsize</span> <span class="ow">and</span> <span class="n">ysize</span><span class="p">:</span>
          <span class="nb">map</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">([</span><span class="n">xsize</span><span class="p">,</span><span class="n">ysize</span><span class="p">])</span>
      <span class="k">else</span><span class="p">:</span>
          <span class="nb">map</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">([</span><span class="n">yrange</span><span class="p">,</span><span class="nb">xrange</span><span class="p">])</span>
      <span class="nb">map</span><span class="p">[</span><span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">yax</span><span class="p">),</span><span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">xax</span><span class="p">)]</span> <span class="o">+=</span> <span class="n">v</span>
      <span class="nb">map</span><span class="p">[</span><span class="nb">map</span><span class="o">!=</span><span class="nb">map</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>

      <span class="k">if</span> <span class="n">dosmooth</span><span class="p">:</span>
          <span class="n">dm</span> <span class="o">=</span> <span class="n">smooth</span><span class="p">(</span><span class="nb">map</span><span class="p">,</span><span class="n">kernelwidth</span><span class="o">=</span><span class="n">smoothpix</span><span class="p">)</span>
          <span class="c">#xax,yax = numpy.indices(map.shape)</span>
          <span class="c">#kernel = gaussfitter.twodgaussian([1,nx/2,ny/2,smoothpix],circle=1,rotate=0,vheight=0)(xax,yax)</span>
          <span class="c">#kernelfft = numpy.fft.fft2(kernel)</span>
          <span class="c">#imfft = numpy.fft.fft2(map)</span>
          <span class="c">#dm = numpy.fft.fftshift(numpy.fft.ifft2(kernelfft*imfft).real)</span>
      <span class="k">else</span><span class="p">:</span>
          <span class="n">dm</span> <span class="o">=</span> <span class="nb">map</span>

      <span class="k">return</span> <span class="n">downsample</span><span class="p">(</span><span class="n">dm</span><span class="p">,</span><span class="n">downsample_factor</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_hdr_string_to_card</span><span class="p">(</span><span class="nb">str</span><span class="p">):</span>
      <span class="n">name</span> <span class="o">=</span> <span class="nb">str</span><span class="p">[:</span><span class="mi">7</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
      <span class="n">val</span>  <span class="o">=</span> <span class="nb">str</span><span class="p">[</span><span class="mi">9</span><span class="p">:</span><span class="mi">31</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
          <span class="n">val</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
      <span class="k">except</span><span class="p">:</span>
          <span class="k">pass</span>
      <span class="n">comment</span> <span class="o">=</span> <span class="nb">str</span><span class="p">[</span><span class="mi">31</span><span class="p">:]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
      <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;END&#39;</span><span class="p">:</span>
          <span class="k">return</span>
      <span class="k">else</span><span class="p">:</span>
          <span class="k">return</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">Card</span><span class="p">(</span><span class="n">name</span><span class="p">,</span><span class="n">val</span><span class="p">,</span><span class="n">comment</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_hdr_string_list_to_cardlist</span><span class="p">(</span><span class="n">strlist</span><span class="p">):</span>
      <span class="n">cardlist</span> <span class="o">=</span> <span class="p">[</span><span class="n">_hdr_string_to_card</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">strlist</span><span class="p">]</span>
      <span class="k">while</span> <span class="bp">None</span> <span class="ow">in</span> <span class="n">cardlist</span><span class="p">:</span> <span class="n">cardlist</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span>
      <span class="k">return</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">CardList</span><span class="p">(</span><span class="n">cardlist</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">itermedian</span><span class="p">(</span><span class="n">ts</span><span class="p">,</span><span class="n">scale</span><span class="o">=</span><span class="mf">0.8</span><span class="p">,</span><span class="n">niter</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
      <span class="n">mts</span> <span class="o">=</span> <span class="n">ts</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
      <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">niter</span><span class="p">):</span>
          <span class="n">mts</span> <span class="o">=</span> <span class="n">mts</span> <span class="o">-</span> <span class="n">numpy</span><span class="o">.</span><span class="n">median</span><span class="p">(</span><span class="n">mts</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)[:,:,</span><span class="n">newaxis</span><span class="p">]</span><span class="o">*</span><span class="n">scale</span>
      <span class="k">return</span> <span class="n">mts</span>

<span class="k">def</span> <span class="nf">boloexp</span><span class="p">(</span><span class="n">xax</span><span class="p">,</span><span class="n">height</span><span class="p">,</span><span class="n">amp</span><span class="p">,</span><span class="n">fjac</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> 
    <span class="c"># set time constant of exponential:</span>
    <span class="n">tc</span><span class="o">=</span><span class="mf">10.4</span> <span class="c">#in seconds</span>
    <span class="n">expterm</span> <span class="o">=</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">xax</span><span class="o">/</span><span class="p">(</span><span class="n">tc</span><span class="o">*</span><span class="mf">50.</span><span class="p">))</span>	<span class="c">#data taken at 50 Hz</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">amp</span> <span class="o">*</span> <span class="n">expterm</span> <span class="o">+</span> <span class="n">height</span>
    <span class="k">return</span> <span class="n">model</span>

<span class="k">def</span> <span class="nf">boloexp_resids</span><span class="p">(</span><span class="n">xax</span><span class="p">,</span><span class="n">data</span><span class="p">,</span><span class="n">mpfit</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">p</span><span class="p">,</span><span class="n">fjac</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="n">model</span> <span class="o">=</span> <span class="n">boloexp</span><span class="p">(</span><span class="n">xax</span><span class="p">,</span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">mpfit</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="mi">0</span><span class="p">,(</span><span class="n">data</span><span class="o">-</span><span class="n">model</span><span class="p">)]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">(</span><span class="n">data</span><span class="o">-</span><span class="n">model</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">f</span>

<span class="k">def</span> <span class="nf">expsub_line</span><span class="p">(</span><span class="n">ts</span><span class="p">,</span> <span class="n">sampleinterval</span><span class="o">=</span><span class="mf">0.04</span><span class="p">,</span> <span class="n">quiet</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="n">xax</span> <span class="o">=</span> <span class="n">arange</span><span class="p">(</span><span class="n">ts</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">*</span> <span class="n">sampleinterval</span><span class="o">/</span><span class="mf">0.02</span>
    <span class="k">if</span> <span class="n">mpfit</span><span class="p">:</span>
        <span class="n">mp</span> <span class="o">=</span> <span class="n">mpfit</span><span class="o">.</span><span class="n">mpfit</span><span class="p">(</span><span class="n">boloexp_resids</span><span class="p">(</span><span class="n">xax</span><span class="p">,</span><span class="n">ts</span><span class="p">,</span><span class="n">mpfit</span><span class="o">=</span><span class="bp">True</span><span class="p">),[</span><span class="mi">0</span><span class="p">,</span><span class="n">median</span><span class="p">(</span><span class="n">ts</span><span class="p">)],</span><span class="n">quiet</span><span class="o">=</span><span class="n">quiet</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">params</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">params</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">params</span> <span class="o">=</span> <span class="n">scipy</span><span class="o">.</span><span class="n">optimize</span><span class="o">.</span><span class="n">leastsq</span><span class="p">(</span><span class="n">boloexp_resids</span><span class="p">(</span><span class="n">xax</span><span class="p">,</span><span class="n">ts</span><span class="p">),[</span><span class="mi">0</span><span class="p">,</span><span class="n">median</span><span class="p">(</span><span class="n">ts</span><span class="p">)])</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">boloexp</span><span class="p">(</span><span class="n">xax</span><span class="p">,</span><span class="o">*</span><span class="n">params</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">ts</span><span class="o">-</span><span class="n">model</span>

<span class="k">def</span> <span class="nf">exponent_sub</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="n">nscans</span><span class="p">,</span><span class="n">ntime</span><span class="p">,</span><span class="n">nbolos</span> <span class="o">=</span> <span class="n">arr</span><span class="o">.</span><span class="n">shape</span>
    <span class="n">subbedarr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">arr</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">nbolos</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">jj</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">nscans</span><span class="p">):</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span><span class="s">&#39;mask&#39;</span><span class="p">):</span>
                <span class="c"># make sure there&#39;s enough data to fit</span>
                <span class="k">if</span> <span class="n">arr</span><span class="o">.</span><span class="n">mask</span><span class="p">[</span><span class="n">jj</span><span class="p">,:,</span><span class="n">ii</span><span class="p">]</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">&lt;</span> <span class="n">ntime</span> <span class="o">-</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">subbedarr</span><span class="p">[</span><span class="n">jj</span><span class="p">,:,</span><span class="n">ii</span><span class="p">]</span> <span class="o">=</span> <span class="n">expsub_line</span><span class="p">(</span><span class="n">arr</span><span class="p">[</span><span class="n">jj</span><span class="p">,:,</span><span class="n">ii</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">subbedarr</span><span class="p">[</span><span class="n">jj</span><span class="p">,:,</span><span class="n">ii</span><span class="p">]</span> <span class="o">=</span> <span class="n">expsub_line</span><span class="p">(</span><span class="n">arr</span><span class="p">[</span><span class="n">jj</span><span class="p">,:,</span><span class="n">ii</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">subbedarr</span>


<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;__main__&quot;</span><span class="p">:</span>

      <span class="c">#from pylab import *</span>
      <span class="c">#from agpy import pyflagger</span>
      <span class="kn">import</span> <span class="nn">sys</span>
      <span class="kn">import</span> <span class="nn">optparse</span>
      <span class="kn">import</span> <span class="nn">pdb</span>

      <span class="n">parser</span><span class="o">=</span><span class="n">optparse</span><span class="o">.</span><span class="n">OptionParser</span><span class="p">()</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--timestreams&quot;</span><span class="p">,</span><span class="s">&quot;-t&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;Plot all timestreams scaled and unscaled as a diagnostic tool.  Default False&quot;</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s">&quot;store_true&quot;</span><span class="p">,</span><span class="n">dest</span><span class="o">=</span><span class="s">&quot;timestreams&quot;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--histograms&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;Plot all weight/scale histograms.  Default False&quot;</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s">&quot;store_true&quot;</span><span class="p">,</span><span class="n">dest</span><span class="o">=</span><span class="s">&quot;histograms&quot;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--weightgrid&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;Plot all weight/scale grids.  Default False&quot;</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s">&quot;store_true&quot;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--plotscan&quot;</span><span class="p">,</span><span class="s">&quot;-p&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;Scan number to plot at the start.  Default to 0.  Set to -1 to turn off.&quot;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--interactive&quot;</span><span class="p">,</span><span class="s">&quot;-i&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;Start in ipython mode?  Default True&quot;</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s">&#39;store_false&#39;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
      <span class="c">#parser.add_option(&quot;--debug&quot;,&quot;-d&quot;,help=&quot;Debug in ipython mode?&quot;,action=&#39;store_true&#39;,default=False)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--no_interactive&quot;</span><span class="p">,</span><span class="s">&quot;-n&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;Turn off ipython (interactive) mode&quot;</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s">&#39;store_false&#39;</span><span class="p">,</span><span class="n">dest</span><span class="o">=</span><span class="s">&quot;interactive&quot;</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--close&quot;</span><span class="p">,</span><span class="s">&quot;-c&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;Close after plotting?  Useful if interactive=False&quot;</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s">&#39;store_true&#39;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--noflag&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;Disable flagging?&quot;</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s">&#39;store_true&#39;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--flag_weights_over&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;*WARNING* This can be dangerous!  Flag all weights over this value.&quot;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="bp">None</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--compute_expfit&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;Do exponential fits to the powerspectra for all bolometers?&quot;</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s">&#39;store_true&#39;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;--compute_powerfit&quot;</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="s">&quot;Do power-law fits to the powerspectra for all bolometers?&quot;</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s">&#39;store_true&#39;</span><span class="p">,</span><span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">set_usage</span><span class="p">(</span><span class="s">&quot;%prog savename.sav [options]&quot;</span><span class="p">)</span>
      <span class="n">parser</span><span class="o">.</span><span class="n">set_description</span><span class="p">(</span>
      <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">      PYFLAGGER </span>
<span class="sd">      &quot;&quot;&quot;</span><span class="p">)</span>

      <span class="n">options</span><span class="p">,</span><span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>

      <span class="n">flag</span> <span class="o">=</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">noflag</span>
          
      <span class="n">plotnum</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">plotscan</span>

      <span class="n">flist</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="n">fdict</span> <span class="o">=</span> <span class="p">{}</span>
      <span class="k">for</span> <span class="n">ii</span><span class="p">,</span><span class="n">filename</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
          <span class="n">prefix</span> <span class="o">=</span> <span class="n">filename</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;_preiter.sav&quot;</span><span class="p">,</span><span class="s">&quot;&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;_postiter.sav&quot;</span><span class="p">,</span><span class="s">&quot;&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;_save_iter0.sav&quot;</span><span class="p">,</span><span class="s">&quot;&quot;</span><span class="p">)</span>

          <span class="k">try</span><span class="p">:</span>
              <span class="n">f</span><span class="o">=</span><span class="n">Flagger</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">flag</span><span class="o">=</span><span class="n">flag</span><span class="p">)</span>
          <span class="k">except</span><span class="p">:</span>
              <span class="n">pdb</span><span class="o">.</span><span class="n">post_mortem</span><span class="p">()</span>
          <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">interactive</span><span class="p">:</span> <span class="k">exec</span><span class="p">(</span><span class="s">&quot;f</span><span class="si">%i</span><span class="s"> = f&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">ii</span><span class="p">)</span> <span class="p">)</span>

          <span class="k">if</span> <span class="n">plotnum</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">:</span> <span class="n">f</span><span class="o">.</span><span class="n">plotscan</span><span class="p">(</span><span class="n">plotnum</span><span class="p">)</span>

          <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">timestreams</span><span class="p">:</span>
              <span class="n">figure</span><span class="p">(</span><span class="mi">6</span><span class="p">)</span>
              <span class="n">clf</span><span class="p">()</span>
              <span class="n">title</span><span class="p">(</span><span class="s">&quot;ac_bolos scaled&quot;</span><span class="p">)</span>
              <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">):</span>
                  <span class="n">f</span><span class="o">.</span><span class="n">timestream_whole</span><span class="p">(</span><span class="n">ii</span><span class="p">,</span><span class="n">timestream</span><span class="o">=</span><span class="s">&#39;acbolos&#39;</span><span class="p">,</span><span class="n">clear</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">fignum</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
              <span class="n">savefig</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">_acbolos_scaled.png&#39;</span> <span class="o">%</span> <span class="n">prefix</span><span class="p">)</span>

              <span class="n">figure</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
              <span class="n">clf</span><span class="p">()</span>
              <span class="n">title</span><span class="p">(</span><span class="s">&quot;ac_bolos unscaled&quot;</span><span class="p">)</span>
              <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">):</span>
                  <span class="n">f</span><span class="o">.</span><span class="n">timestream_whole</span><span class="p">(</span><span class="n">ii</span><span class="p">,</span><span class="n">timestream</span><span class="o">=</span><span class="s">&#39;acbolos_noscale&#39;</span><span class="p">,</span><span class="n">clear</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">fignum</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
              <span class="n">savefig</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">_acbolos_noscale.png&#39;</span> <span class="o">%</span> <span class="n">prefix</span><span class="p">)</span>

          <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">weightgrid</span><span class="p">:</span>
              <span class="n">figure</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
              <span class="n">clf</span><span class="p">()</span>
              <span class="n">f</span><span class="o">.</span><span class="n">weightgrid</span><span class="p">()</span>
              <span class="n">savefig</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">_weightscalegrid.png&#39;</span> <span class="o">%</span> <span class="n">prefix</span><span class="p">)</span>

          <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">histograms</span><span class="p">:</span>
              <span class="n">figure</span><span class="p">(</span><span class="mi">8</span><span class="p">)</span>
              <span class="n">clf</span><span class="p">()</span>
              <span class="n">f</span><span class="o">.</span><span class="n">histograms</span><span class="p">()</span>
              <span class="n">savefig</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">_weightscalehistograms.png&#39;</span> <span class="o">%</span> <span class="n">prefix</span><span class="p">)</span>

          <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">flag_weights_over</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
              <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">flag_weights_over</span> <span class="o">&gt;=</span> <span class="mi">200</span><span class="p">:</span>
                  <span class="n">f</span><span class="o">.</span><span class="n">flags</span><span class="p">[</span><span class="n">f</span><span class="o">.</span><span class="n">weight</span> <span class="o">&gt;</span> <span class="n">options</span><span class="o">.</span><span class="n">flag_weights_over</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
                  <span class="n">f</span><span class="o">.</span><span class="n">writeflags</span><span class="p">()</span>

          <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">compute_powerfit</span><span class="p">:</span>
              <span class="n">ppars0</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">])</span>
              <span class="n">ppars1</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">])</span>
              <span class="n">ppars2</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">])</span>
              <span class="n">gstd</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">)</span>
              <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">):</span>
                  <span class="k">try</span><span class="p">:</span>
                      <span class="n">ppars0</span><span class="p">[:,</span><span class="n">ii</span><span class="p">],</span><span class="n">ppars1</span><span class="p">[:,</span><span class="n">ii</span><span class="p">],</span> <span class="n">ppars2</span><span class="p">[:,</span><span class="n">ii</span><span class="p">],</span> <span class="n">gstd</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">broken_powerfit</span><span class="p">(</span><span class="n">ii</span><span class="p">,</span><span class="n">timestream</span><span class="o">=</span><span class="s">&#39;ac_bolos&#39;</span><span class="p">)</span>
                  <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                      <span class="k">print</span> <span class="s">&quot;Bolo </span><span class="si">%i</span><span class="s"> is probably flagged out.&quot;</span> <span class="o">%</span> <span class="n">ii</span>
              <span class="k">print</span> <span class="s">&quot;Median(gstd) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">gstd</span><span class="p">)</span>
              <span class="k">print</span> <span class="s">&quot;Median(ppars0[0,:]) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">ppars0</span><span class="p">[</span><span class="mi">0</span><span class="p">,:])</span>
              <span class="k">print</span> <span class="s">&quot;Median(ppars0[1,:]) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">ppars0</span><span class="p">[</span><span class="mi">1</span><span class="p">,:])</span>
              <span class="k">print</span> <span class="s">&quot;Median(ppars1[0,:]) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">ppars1</span><span class="p">[</span><span class="mi">0</span><span class="p">,:])</span>
              <span class="k">print</span> <span class="s">&quot;Median(ppars1[1,:]) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">ppars1</span><span class="p">[</span><span class="mi">1</span><span class="p">,:])</span>
              <span class="k">print</span> <span class="s">&quot;Median(ppars2[0,:]) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">ppars2</span><span class="p">[</span><span class="mi">0</span><span class="p">,:])</span>
              <span class="k">print</span> <span class="s">&quot;Median(ppars2[1,:]) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">ppars2</span><span class="p">[</span><span class="mi">1</span><span class="p">,:])</span>
              <span class="k">print</span> <span class="s">&quot;WARNING! This likely only applies to astrosignal, NOT ac_bolos!&quot;</span>

          <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">compute_expfit</span><span class="p">:</span>
              <span class="n">ppars1</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">])</span>
              <span class="n">ppars2</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">])</span>
              <span class="n">gstd</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">)</span>
              <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">nbolos</span><span class="p">):</span>
                  <span class="k">try</span><span class="p">:</span>
                      <span class="n">ppars1</span><span class="p">[:,</span><span class="n">ii</span><span class="p">],</span> <span class="n">ppars2</span><span class="p">[:,</span><span class="n">ii</span><span class="p">],</span> <span class="n">gstd</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">broken_expfit</span><span class="p">(</span><span class="n">ii</span><span class="p">,</span><span class="n">timestream</span><span class="o">=</span><span class="s">&#39;ac_bolos&#39;</span><span class="p">)</span>
                  <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                      <span class="k">print</span> <span class="s">&quot;Bolo </span><span class="si">%i</span><span class="s"> is probably flagged out.&quot;</span> <span class="o">%</span> <span class="n">ii</span>
              <span class="k">print</span> <span class="s">&quot;Median(gstd) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">gstd</span><span class="p">)</span>
              <span class="k">print</span> <span class="s">&quot;Median(ppars1[0,:]) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">ppars1</span><span class="p">[</span><span class="mi">0</span><span class="p">,:])</span>
              <span class="k">print</span> <span class="s">&quot;Median(ppars1[1,:]) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">ppars1</span><span class="p">[</span><span class="mi">1</span><span class="p">,:])</span>
              <span class="k">print</span> <span class="s">&quot;Median(ppars2[0,:]) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">ppars2</span><span class="p">[</span><span class="mi">0</span><span class="p">,:])</span>
              <span class="k">print</span> <span class="s">&quot;Median(ppars2[1,:]) = </span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">median</span><span class="p">(</span><span class="n">ppars2</span><span class="p">[</span><span class="mi">1</span><span class="p">,:])</span>
              <span class="k">print</span> <span class="s">&quot;WARNING! This likely only applies to astrosignal, NOT ac_bolos!&quot;</span>

          <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">close</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">interactive</span><span class="p">:</span>
              <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">write</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
              <span class="k">del</span> <span class="n">f</span> 
          <span class="k">else</span><span class="p">:</span>
              <span class="n">flist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
              <span class="n">fdict</span><span class="p">[</span><span class="n">f</span><span class="o">.</span><span class="n">filename</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span>


      <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">interactive</span><span class="p">:</span>
          <span class="k">try</span><span class="p">:</span>
              <span class="kn">from</span> <span class="nn">IPython.Shell</span> <span class="kn">import</span> <span class="n">IPShellEmbed</span>
              <span class="n">ipshell</span> <span class="o">=</span> <span class="n">IPShellEmbed</span><span class="p">([])</span>
              <span class="n">ipshell</span><span class="p">()</span> <span class="c"># this call anywhere in your program will start IPython</span>
          <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
              <span class="kn">from</span> <span class="nn">IPython</span> <span class="kn">import</span> <span class="n">embed</span>
              <span class="n">embed</span><span class="p">()</span>
</pre></div>

          </div>
        </div>
      </div>
        </div>
        <div class="sidebar">
          <h3>Table Of Contents</h3>
          <ul>
<li class="toctree-l1"><a class="reference internal" href="../../agpy.html">Adam Ginsburg&#8217;s Python Code (agpy)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../image_tools.html">Image Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fft_tools.html">AG_fft_tools Package</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../plfit.html">plfit Package</a></li>
</ul>

          <h3 style="margin-top: 1.5em;">Search</h3>
          <form class="search" action="../../search.html" method="get">
            <input type="text" name="q" />
            <input type="submit" value="Go" />
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>
          <p class="searchtip" style="font-size: 90%">
            Enter search terms or a module, class or function name.
          </p>
        </div>
        <div class="clearer"></div>
      </div>
    </div>

    <div class="footer">
      &copy; Copyright 2011, Adam Ginsburg.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2pre.
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-6253248-2']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
        
    </div>
  </body>
</html>